Answer a question

I basically want to redirect to the previous url when a user has successfully logged in.

I redirect to the login page with the previous url such as /login?redirect=/page1/page2.

And I want when a user authenticates to be redirected back to that url. I am using the auth-module here: https://auth.nuxtjs.org/

How I login the user.

methods: {
    async submit() {
      await this.$auth.loginWith('local', {
        data: this.form
      })
    }
}

The only thing that I could found in the docs is this: https://auth.nuxtjs.org/getting-started/options#redirect

which however only redirects to a specific page instead of the previous page in the query.

Any ideas on how to achieve this?

Answers

You Can Do This

  this.$router.back()

And its go back to the last route.

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

Thanks.

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐