How do I get the previous route address?
Unanswered
Orinoco Crocodile posted this in #help-forum
Orinoco CrocodileOP
How do I get the previous route address in nextJS? I'm redirecting to my login window and want to return to the previous screen on complete
7 Replies
Orinoco CrocodileOP
bump
Check window.history
but ideally you would pass a query param to the rediection
like "login?from=/home"
use "encodeURIComponent" (and decodeURIComponent) in order to be able to shove a path into the URL while handling special chars
note that it makes the login page dynamic if you get searchParams from props, or client-side rendered if you use useSearchParams
Orinoco CrocodileOP
Thanks!