I am able to use this.$router.go(-1)
to redirect a user to the previous route. However, I am not able to understand how I get get the information about the previous route before redirecting.
Basically, by first reading what the previous route was, I want to make sure that the previous route was from the same domain and only then redirect to it, otherwise do something else.
In your page you can add asyncData
hook which have access to context
object with from
property:
asyncData({ from }) {
console.log(from);
}
in nuxt static methods where you have access to nuxt context ex: asyncData or middlewares
:
asyncData({from}){
// do something with from
}
but if you want to get the prev route in vue instance you can use
this.$nuxt.context.from
also, remember that from
can be undefined if there wasn't any prev page in the browser history
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With