Sathish Kumar VG
Sathish Kumar VG

Reputation: 2172

Reactjs Router version4 Routing issue

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

Answers (1)

Winter
Winter

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:

  1. there is no <div> around the routes, they are encapsulated with a path='/' to indicate the root component
  2. I have an index route also which tells the router which component should be shown by default

Upvotes: 1

Related Questions