found icon indicating copy to clipboard operation
found copied to clipboard

useLocation vs router Location Props while navigating

Open eMerzh opened this issue 1 year ago • 1 comments

Hello, i face some kind of trouble here... maybe it's a misunderstanding.

i have found + found relay, i have a bunch of routes using getComponent to get the appropriate render,

If in my route i use the useLocation for example to get the location params somewhere down the tree, i might receive at some point params that are totally not related to the current route (and clear the params related to this one)

for example

route: path: blog-post/:id getComponent() => BlogPost

route: path: tag/:id getComponent() => Tag

if i navigate from blogpost/12 , to tag/23 route, and BlogPost use a useParams() , then BlogPost will receive id: 23 which is a bit strange ...

the issue does not occurs if a take the param from the match props.

but then it makes the useLocation/useParams hook pretty hard to use 🤔

could you help me?

Thanks :)

eMerzh avatar Sep 23 '24 07:09 eMerzh

useParams just uses useMatch same with useLocation they all use the same underlying properties off of match so i'm not sure how you'd get different results between them. I'd need a reproduction to try and see what's going on.

I will say that found doesn't give params related to any specific route, it always provides all the params for the matched location. However it's not generally expected that the previous route is given the new params on a navigation since it should render the new route

jquense avatar Oct 03 '24 13:10 jquense