T
TanStack•2y ago
stormy-gold

Best approach for navigation back and forward?

I wonder what's the best way to handle situations like that: - let's say I have paginated page /posts - /posts/1 is a single post page which has 'back' link inside If there would be no such a button, user would be forced to use browser navigation which would go back to the previous page (not push another route). As far as I understand, I can use history.go(-1), but if user has just directly opened the /posts/1 page , that would redirect him to the page he initialy came from. Of course I can pass some search params like backURL, but the downside of this is that it pushes a new route to the history. Is there something like in-app router history, that would remember the previous in-app pages? I hope it's not a stupid question 🙂
1 Reply
conscious-sapphire
conscious-sapphire•2y ago
We use the browser standards as much as possible so, when we call router.history.back(), it calling the browser API for it. But to answer you question, you can do this by tracking your previous page state in something like a search params. /posts/1?postsListState={page: 2, size: 10} and create you breadcrumb navigation links off of that. This would be similar to your backURL suggestion I suppose.

Did you find this page helpful?