leptos icon indicating copy to clipboard operation
leptos copied to clipboard

RouteContext.path() stops updating when you press the back button

Open Innominus opened this issue 2 years ago • 1 comments

When using use_route(cx) to get the RouteContext, calling .path() works and gives you the correct route. But upon using the back button .path() stops updating its underlying value, and will give you the same route.

In my situation, I'm using the route context path to navigate to nested routes as I'm not using an A tag. I'm just adding to the end of the path returned with a route param, :recipe. This works, and I can navigate to other pages and then to this nested route. If I go to the nested route, then press back, the path getter on RouteContext will return the wrong path. Examples: Normal route, where you can click the recipe below on the page to navigate into it image From this page, instead of navigating back using the in-app navigation, I press the back button. image I navigate normally to another route and the click into the below panel/recipe to navigate to that nested route image Nested route's parent route is overwritten with tabbed, instead of Nonna's greatest recipes image

I just did some testing and it turns out from some quick testing that this path value doesn't change at all when I navigate to new paths in the same route that relies on a route param. Even without pressing the back button. This might be intentional, or a bug. As I'm technically not navigating to a new route, but changing the params for the current one.

I will definitely try get a minimal example repo up and running to replicate this behaviour soon to better illustrate.

Innominus avatar Jan 19 '23 10:01 Innominus

Yeah, interesting. path() explicitly returns a non-reactive type, so I wouldn't expect it to update. use_context() is also not reactive. Maybe try using use_location instead, which returns a reactive Location struct that may be better suited to your needs — or track one of its reactive fields in an effect and call use_context within that so you are always getting an up-to-date path.

Let me know if that's a suitable solution.

gbj avatar Jan 19 '23 13:01 gbj

Thanks for the reply :) everytime I navigate I'm explicitly calling use_route again and getting .path() again. I'm not storing it, or using it reactively, but using it in a function. My assumption would be that these fresh contexts would contain the current data. If this isn't intended, no worries! I opted to use location from the Window object in the meantime. Just assumed this was a bug.

Innominus avatar Jan 19 '23 20:01 Innominus