question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Router Not Working

See original GitHub issue

I am having trouble using React Router to create another static page within my app.

Here is what my render method looks like:

ReactDOM.render(
 <Router history={hashHistory}>
  <Route path="/" component={Home}>
     <Route path="material" component={Material}/>
   </Route>
 </Router>,
 document.getElementById('root')
);

When I try to visit localhost:8080/material, the url redirects to localhost:8080/material#/ and I the page just loads Home instead of Material. There is no way for me to access my Material Component.

The same error occurs when I reconfigure the render method to look like this:

ReactDOM.render(
 <Router history={hashHistory}>
  <Route path="/" component={Home}/>
  <Route path="/material" component={Material}/>
 </Router>,
 document.getElementById('root')
);

What do I have to do to get access to different routes? edit: forgot question mark

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tamaccountcommented, Mar 13, 2017

Thank you everyone for the help!

2reactions
gaearoncommented, Mar 13, 2017

If you want to use the browser history, you should pass the browserHistory instead.

import { browserHistory } from 'react-router';

ReactDOM.render(
 <Router history={browserHistory}>

I hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React route is not working | React Router - Stack Overflow
If the issue is that you've installed react-router-dom version 6 and you are working from an outdated tutorial, then replace the Switch ......
Read more >
Routes not working in react router - Questions - OneCompiler
The problem is with the Nav Route, It is the base route to all routes. So, you need to tell react router that...
Read more >
Why is my react Router not working - The freeCodeCamp Forum
im gonna try adding some GET requests for those url's in the server but I know there must be a nicer way. By...
Read more >
React Router Frequently Faced Problems | by Shoaib Bhimani
If you have declared component and it is not rendering It could be below three Issues. First, if you are using any state...
Read more >
React router page links not working in production : r/reactjs
You need to get your web host to serve the react bundle for all routes. Normally, it'll only serve the index.html for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found