How to Clear Multiple Routes from Navigation History in TanStack Router
Navigation Flow:
- Start at
/account/networks
- navigate({ to: "/account/networks/search" })
- navigate({ to: "/account/networks/search/join-dialog" })
- After success action, we want to return to /account/networks
The Issue:
When using replace: true to navigate back to /account/networks:
- Navigation to /account/networks works
- But then router.history.back() at /account/networks takes user to /account/networks/search
- We want it to go back to /account
- We need to clear both the search and join-dialog routes from history
Is there a way to clear multiple routes ( both the search and join-dialog routes) from the history stack in TanStack Router?Navigation Flow:4 Replies
ratty-blush•2mo ago
did you ever figure out a solution for this? Dealing with a similar problem
@Manuel Schiller sorry for the ping but wondering if you have any insights for this question? I have a similar situation where:
1. Navigate to pages scoped to a specific resource e.g.
/projects/$projectId/...
2. Perform an action that removes access to $projectId, navigating to a completely different subpath. something like /onboarding/...
The page(s) in (2) have a back button that ideally use the history.back() if possible but that results in being able to access the page in (1) since it's still in the history.like-gold•2mo ago
i assume you are using the browser history?
this does not provide an API other than replacing the current entry
ratty-blush•2mo ago
technically using the hash history
like-gold•2mo ago
which still is based on brower history