TanStackT
TanStack9mo ago
6 replies
standard-azure

differentiate navigation due to router.navigate vs browser navigation

Is there any way to determine if searchParams change due to my own call of router.navigate vs the user/browser navigating with the forward/back buttons for example?

context:
im trying to have my app state represented in the url, and also allow the user to navigate between urls with different search params and load the state appropriately.

the issue im running into is i have a useEffect depending on the searchParams that updates state.
I also have a useEffect depending on state that updates the url. These can get into a loop. Even with some early returns from the useEffects to prevent a loop, i cant get a set up that properly achieves the above goal. If i could reliably determine that searchParams changed due to a browser action rather than my own, then i could make each useEffect only run at the correct time.
Was this page helpful?