I fiddled with react-router , binding to implementing simple routing. I am typing my code as written in their example (but without import s) https://github.com/rackt/react-router#whats-it-look-like .
And I get this error in the browser:
Unfixed error: invariant violation: element type is invalid: expected string (for built-in components) or class / function (for composite components), but received: object.
That's what I'm doing.
I am attaching scripts on the ReactRouter.min.js page and my code in react-routes.js . And also react and react-dom and jquery (all three in app.js ):
<script src="/js/app.js" type="text/javascript" charset="utf-8"></script> <script src="https://npmcdn.com/react-router/umd/ReactRouter.min.js"></script> <script src="/js/react-routes.js" type="text/javascript" charset="utf-8"></script>
Here is my react-router.js not yet compiled:
'use strict'; window.Router = window.ReactRouter; window.Link = window.ReactRouter.Link; window.Route = window.ReactRouter.Route; const Foo = React.createClass({ render() { return ( <div> <h1>HELLO, me FOO</h1> </div> ) } }); ReactDOM.render(( <Router> <Route path="/" > <Route path="/page/one" component={Foo}/> </Route> </Router> ), document.getElementById('content-section'))
This is my react-router.js after compiling with Babylon. I attach exactly this on the page:
babel --presets react -o public/js/react-routes.js assets/js/react-routes.js :
'use strict'; window.Router = window.ReactRouter; window.Link = window.ReactRouter.Link; window.Route = window.ReactRouter.Route; const Foo = React.createClass({ displayName: "Foo", render() { return React.createElement( "div", null, React.createElement( "h1", null, "HELLO, me FOO" ) ); } });
How am I wrong? Why does an error occur? A router is an object, not a React component. What for? I look at this example and find my code also https://github.com/rackt/react-router#whats-it-look-like