2

I have a component that imports a Router and it isn't working and there isn't any error message. The pages aren't appearing on the browser. It is a course s' app. Because of the fact that this course is a bit old, some things could be overpast. Here are the codes of my components:

import '../common/template/dependencies'
import React from 'react'    

import Routes from './Routes'

export default props => (
  <div className='wrapper'>   
    <div className='content-wrapper'>
     <Routes />
     </div>
  </div>
)

The component Routes.js that does the routing:

import React from 'react'
import {Router, Route , Redirect, hasHistory} from 'react-router'

import Dashboard from '../dashboard/Dashboard'
import BillingCycle from '../billingCycle/BillingCycle'

export default props => (
  <Router history={hasHistory}>
    <Route path='/' component={Dashboard} />
    <Route path='/billingCycles' component={BillingCycle} />
    <Redirect from='*' to='/' />
  </Router>
)

When I comment this line of the component above, everything works well.

  {/*<Routes />*/}
6
  • what is Dashboard component have ? Commented Mar 3, 2019 at 5:26
  • This component has only a h1: <h1>Dashboard</h1> because we are in the beginning of the construction of the app Commented Mar 3, 2019 at 5:27
  • did you try adding exact to your / path and putting it after /billingCycles? Commented Mar 3, 2019 at 5:32
  • Yes. I tried it now and it didn't work Commented Mar 3, 2019 at 5:38
  • Why are you not using react-router-dom? stackoverflow.com/questions/42684809/… Commented Mar 3, 2019 at 5:57

2 Answers 2

3
import React from 'react'
import {BrowserRouter as Router, Route, Redirect, Switch} from 'react-router-dom';
import Dashboard from './DashBoard';
import BillingCycle from './BillingCycle'

export default props => (
    <Router>
        <Switch>
            <Route exact path='/' component={Dashboard}/>
            <Route exact path='/billingCycles' component={BillingCycle}/>
            <Redirect from='*' to='/'/>
        </Switch>
    </Router>

)

Check your code does hasHistory is available in new version react-router. Also you should use react-router-dom. Hope this helps..

Sign up to request clarification or add additional context in comments.

Comments

0

Use react-router-dom

Change your import in Route.js like this:

import {BrowserRouter as Router, Route} from 'react-router-dom'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.