Reputation: 2172
I am using react-router version 4,as routing configuration for the component is done,but the component is not mounted as I tried with componentDidMount() method,the console log is not shown.
Here is my code,
import { Route,Switch,hashHistory } from 'react-router';
import {HashRouter as Router} from 'react-router-dom';
import { createHistory, useBeforeUnload } from 'history';
<Router history={hashHistory}>
<div>
<Route exact path='/userlogin/' component={LoginPage}></Route>
<Route exact path='/dashboard/' component={Dashboard}></Route>
<Route exact path='/forgotpassword/' component={ForgotPasswordPage}></Route>
</div>
</Router>
As the page is coming empty when i tried with router url path of component.
Any help is appreciated.Thanks in advance.!
Upvotes: 0
Views: 83
Reputation: 2517
My routes look like this:
var routes = (
<Router history={browserHistory}>
<Route path='/' component={Main}>
<IndexRoute component={Home} />
<Route path='chapters' component={ChapterListContainer} />
<Route path='chapters/chapter:id' component={ChapterPageContainer}></Route>
</Route>
</Router>
);
There are a couple of differences:
<div>
around the routes, they are encapsulated with a
path='/'
to indicate the root componentUpvotes: 1