Next.js Discord

Discord Forum

How do I get the previous route address?

Unanswered
Orinoco Crocodile posted this in #help-forum
Open in Discord
Avatar
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

Avatar
Orinoco CrocodileOP
bump
Avatar
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
Avatar
Orinoco CrocodileOP
Thanks!