Summary I need to run React Router without using wepback or similar tools. Straight from the CDN links, but I'm stuck with some require.js error.
I am starting to build my first application using React, and I am struggling with React Router.
HTML:
<body> <div id="container"></div> <script src="https://unpkg.com/ react@15 /dist/react.js"></script> <script src="https://unpkg.com/ react-dom@15 /dist/react-dom.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.js"></script> <script src="https://npmcdn.com/ react-router@2.4.0 /umd/ReactRouter.js"></script> <script type="text/babel" src="assets/scripts/03_templates/app.js" charset="utf-8"></script> </body>
JS:
var { Router, Route, IndexRoute, hashHistory, IndexLink, Link, browserHistory } = ReactRouter; //some classes ReactDOM.render(( <Router history={hashHistory}> <Route path="/" component={Window}> <IndexRoute component={InitialPage}/> <Route path="register" component={Register} /> <Route path="search" component={Search} /> </Route> </Router> ), document.getElementById("container"));
Everything works fine, but I get this on the console:
react.js: 3639 Warning: you manually call the React.PropTypes validation function for getComponent prop on IndexRoute . This one is outdated and will not work in production with the next major version. Perhaps you see this warning due to the third-party PropTypes library.
So, I suppose my Router is an old version. I changed the link to
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-0/react-router.js"></script>
Warning: React.createElement: the type must not be null, undefined, boolean or number. It must be a string (for DOM elements) or a ReactClass (for composite components).
I am looking for this and the problem seems to be on line 1. So I changed this:
var { Router, Route, IndexRoute, hashHistory, IndexLink, Link, browserHistory } = ReactRouter;
For this:
import { Router, Route, IndexRoute, hashHistory, IndexLink, Link, browserHistory } from 'react-router';
And now I have this problem:
app.js: 2 Uncaught ReferenceError: require not defined
I searched for require.js, tried some things, but nothing fixed my problem. What am I missing? I need to run this without webpack tools or similars.
thanks