Skip to content
Advertisement

Is there a way to not reload the whole html body with React Routers?

My React project’s App.js file has routes like so:

JavaScript

In my Navbarr component, I have Links that set the routes, e.g.:

JavaScript

When I click on any of the links, I would like it to just change the component in my <Switch>. Instead, it seems to re-load the whole html body (my background component flashes, even though it has the same picture).

Is there a way to do this?

Advertisement

Answer

You can use react-router-dom‘s Link and use to prop instead of href to use client-side-routing

JavaScript

Alternatively, you can leverage the as prop of React-bootstrap

JavaScript
Advertisement