[Vuejs]-Get previous URL for use in redirect

1👍

It seems that the next({ name: 'Login' }) call you use to redirect to the login page doesn’t modify the from attributes. That is because you are “internally” routing, it is different from making a router.push call.

Probably the easiest way to do this kind of redirect is by using a query param:

next({
  name: "bar",
  query: { redirect: to.fullPath }
});

Then access it either in your component $route.query.redirect or in a router navigation guard from.query.redirect.

4👍

You could just do this..

this.$router.back();

This will take you back to the previous route

Programmatic Navigation | Vue Router https://router.vuejs.org/guide/essentials/navigation.html

-1👍

To go back the previous route you can use

this.$router.go(-1)

vue maintains history of previous visited routes.

-1 mean go back one record.

see https://router.vuejs.org/guide/essentials/navigation.html#router-go-n

Leave a comment