Next.js Discord

Discord Forum

Previuos route

Answered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
I am trying to get the previouse route name.
I have a page (/catalog) that can go to another page (/item)
In the page (/catalog), how do I keep track that I was redirected from (/item) ?
route.back would just go back, but I want to keep track of the previous path
Answered by ᴉuɐpɹɐɐ
You can store the previous link in a localStorage before redirecting to another page. This is done by creating a custom <Link> wrapper
View full answer

3 Replies

You can store the previous link in a localStorage before redirecting to another page. This is done by creating a custom <Link> wrapper
Answer
or you can store the previous link in a searchParam but that would be a bit ugly
Asiatic LionOP
Thanks! thats a good idea