N
Nuxt7mo ago
Giuliopime

How to get previous route from inside a page?

I have a login page and I need to save the previous route before the user navigated to /login so I can then redirect him there after logging in. It's a simple thing but I looked everywhere and can't see to find the navigation stack data anywhere. Can anyone delucidate me on this? thxxx
7 Replies
Giuliopime
GiuliopimeOP7mo ago
PS: I don't wanna pass a query parameter for that
pyplacca
pyplacca7mo ago
you can use a global state like useState. If you have a store set up, you can also use that
pyplacca
pyplacca7mo ago
assuming you don't know how to get the previous route, you can use a route middleware
Nuxt
defineNuxtRouteMiddleware · Nuxt Utils
Create named route middleware using defineNuxtRouteMiddleware helper function.
owljackob
owljackob7mo ago
Try checking Vue router's docs.
rxsto
rxsto7mo ago
rxsto
rxsto7mo ago
it'll have the value .back, containing the previous route as in
useRouter().options.history.state.back
useRouter().options.history.state.back
pyplacca
pyplacca7mo ago
that's nice. TIL
Want results from more Discord servers?
Add your server