Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to login without add route to history record in vue?

I'm on the page: /foo and click on the button to redirect me to /bar. But I have beforeEach route event which redirect me to /login. after I do login, I redirect to /bar.

When I on /bar I click on the back button I get to login page. instend I want to get the the last page which is /foo.

How can I do it? is there a way to redirect to login without add route to history record?

  router.beforeEach((to, from, next) => {
    if (!to.matched.some((record) => record.meta.auth)) { return next(); }

    return next({
      path: '/login',
    });
  });
like image 207
Jon Sud Avatar asked Sep 11 '25 19:09

Jon Sud


1 Answers

Use replace instead of push when you redirect to the page after login (in the login component).

loginSuccessed() {
 this.$router.replace(redirect);
}
like image 148
Shlomi Levi Avatar answered Sep 16 '25 09:09

Shlomi Levi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!