S
SolidJS10mo ago
Max

file routes callbacks on parameter change or top level useParams

Wondering if there's a good way to get and use route parameters either outside of the render process or on a level where it is called every route change, regardless of matches route. I don't think that's explained so well but cant really find the words for that right now. But the situation is basically that I would like to run some effect or even regular function whenever a parameter may change. But there are multiple routes and route files that may be matches (e.g. just /a, /a/b ..etc ). And I would like to avoid putting the same useParams call on each route component. A callback on the router or similar would maybe be close to what I'm looking for, just any information would be great, thanks.
2 Replies
ai6
ai610mo ago
Can you not just have useLocation in root.tsx and use createEffect to track it?
Max
Max10mo ago
Thanks, yea I don't think in root is possible because FileRoutes is rendered inside root.tsx I would assume useLocation should be called within the scope of FileRoutes. I tried also to check but with useParams at least that didn't work. Pretty much did something similar though just some other component that's fairly high up in the rendering so works okay.