Change the Route without Fetching that routes content

Viewed 30

So I know this doesn't sound like a good case, but I'm trying only to change the browser link on React using React Router without loading that page it selfs, in case the user reloads the page then fetches it because it matches the route, I'm trying to use this so when the user saves the product on the preview page to not redirect to the new id so I can fetch the data, this will be consuming, rather I want to manipulate the URL so that everything is on its place.

I tried this using useNavigate, I think and will do the same, I think I saw some websites have something similar implemented.

Here again what I do have for the start, this fetches the page:

import { useNavigate } from "react-router-dom";
...
const to = useNavigate();
...
<p onClick={() => to('/product/stackoverflow-shirt')}>!don't fetch the content</p>
1 Answers

I found the solution to my problem, but not with React Router, rather the native method that Window provides.

Here we go:

window.history.replaceState({}, ‘’, ‘/newSlug’)
Related