reactjs - react-router.min.js:1 Uncaught TypeError: Cannot read property 'location' of undefined -
<!-- included script --> <script src="https://unpkg.com/react@15/dist/react.min.js"></script> <script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script> <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script> <script src="https://unpkg.com/react-router/umd/react-router.min.js"></script> <div id="root"></div> <script type="text/babel"> var router = reactrouter.router; var route = reactrouter.route; var indexroute = reactrouter.indexroute; var link = reactrouter.link; var browserhistory = reactrouter.browserhistory; class page extends react.component { render() { return ( <div> <link to='/about'>india </link> </div> ); } } class extends react.component { render() { return ( <div> router </div> ); } } class nomatch extends react.component { render() { return ( <div> no page found </div> ); } } reactdom.render( <router> <route path="/" component={page}> <route path="about" component={about}/> <route path="*" component={nomatch}/> </route> </router>, document.getelementbyid('root') ); </script>
it give me 'location' of undefined error. have tried slimier answers in other posts still not working me.
can 1 me solve issue?
thanks in advance.
react-router-dom
use react-router-dom
( dom bindings react router)
install
<script src="https://unpkg.com/react-router-dom/umd/react-router-dom.min.js"></script>
use
just use reactrouterdom
instead of reactrouter
:
var router = reactrouterdom.browserrouter; var route = reactrouterdom.route; var link = reactrouterdom.link;
you can find library on window.reactrouterdom.
basic example
<router> <div> <route exact path="/" component={home}/> <route path="/news" component={newsfeed}/> </div> </router>
Comments
Post a Comment