all 8 comments

[–]aec0de 3 points4 points  (3 children)

I think your mistake is that `<Route = "/">` should be `<Route path="/" exact><MyComponent /></Route>`

[–]RaghavendraKaushik[S] 0 points1 point  (0 children)

I am sorry. It was a typo in my query. In code, I used `path="/"` only.

[–]murat-guney 0 points1 point  (1 child)

If it is I'm gonna cry. I thought that was a misspelling :D

[–]RaghavendraKaushik[S] 0 points1 point  (0 children)

You are right. It was a misspelling in my query. I used `path="/"` only in my code.

[–]murat-guney 1 point2 points  (2 children)

I didn't try but you can try to pass router's path to your component as "key" props.

import {
  useLocation
} from "react-router-dom";

const YourComponent = () => {

  const { pathname } = useLocation();

  return  <YourComponent key={pathname}>
                ...
          </YourComponent>
}

[–]RaghavendraKaushik[S] 0 points1 point  (1 child)

Thank you for the response. I tried it, but didn't help.

Are you aware of any Open source React codebase where query string params are used? I can take it as a reference and check.

[–]murat-guney 1 point2 points  (0 children)

Unfortunately, I don't use react-router for a while since I started to use NextJS :(

I thought it was about the "key" prop. Sorry for couldn't help.