4Catalyzer / found

Extensible route-based routing for React applications
https://4catalyzer.github.io/found/
MIT License
793 stars 55 forks source link

useLocation vs router Location Props while navigating #1064

Open eMerzh opened 3 weeks ago

eMerzh commented 3 weeks ago

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 :)

jquense commented 1 week ago

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