happyZZR1400 happyZZR1400 - 3 months ago 12
Javascript Question

cannot configure react-router to run on plunkr

i'm starting to teach myself react now and i currently starting to play with react-router.
For some reason ,my project cannot run with Router tag on this plunkr

<Router history={browserHistory}>
<Route path="/" component={SearchPage}></Route>
</Router>


The error is "Router not defined"

I know - very basic question, but may be thats reason it will be very easy to answer

Thanks

Answer
  1. you can use it something like that (es6):

    const {Router, Link, hashHistory, Route, withRouter} = ReactRouter;
    

    http://plnkr.co/edit/SzowouqjShMZiiXtlD5b?p=preview

  2. or if you prefer es5

    var Router = ReactRouter.Router;
    var Route = ReactRouter.Route;
    var hashHistory = ReactRouter.hashHistory;
    

    http://plnkr.co/edit/UznT9V3aMnvzVfsI5ua7?p=preview

  3. also you can use es6 modules with webpackbin

    import {Router, Route, hashHistory} from 'react-router';
    

    http://www.webpackbin.com/Ny87fO0Kb

Comments