DEV Community

lughjw
lughjw

Posted on

A React Router Bug Tip

I started learning React recently and wanted to focus on the Router component. Here I'll post a few things I learn as I go through it. I'll update this as I come across new tidibts.

  • If you're clicking on a Link and it's not taking you anywhere but it is changing your url, then check to make sure that the link is within your Router component (Be that a BrowserRouter, HashRouter, MemoryRouter, etc). It can be nested within children which are in the Router, but needs to be within the Router. An example:
<Router>
    <NavBar />
    <Route exact path="/" render={(props) => <MyComponent {...props} />} />
    {/* Other Routes here */}
</Router>

Top comments (0)