Skip to content
Advertisement

React routing to endpoint but not rendering content

I can route to another endpoint, but the component content only appears on manual refresh.

I’ve seen this question asked here, here, and I’ve been checking out the reactrouter docs, amongst others. The solution always seems to be “add withRouter” or “make sure you’re wrapping it in Router. I’ve done those things, but sadly got no where.

Here’s the code:

App.js

JavaScript

NavBar.js

JavaScript

EDIT: After comment suggestions, here’s a code sandbox link and here;s the Account.js page:

JavaScript

Advertisement

Answer

The Problem here is that, in your Navbar.js, you are re-setting your Routes again when they are already set in App.js.

JavaScript

You do not need to do that again in. Check here.

https://codesandbox.io/s/gracious-germain-7fyry?file=/src/Navbar.js

Your Nabar should look like:

JavaScript
Advertisement