steve
steve

Reputation: 1428

Why the router.go() does not work in Vue Router?

Using vue-router, I have a component check user login status, how can I redirect to the login page URL using the router?

In component, my code:

<script>
  export default {
    components: {
    },
   
    name: 'landing-page',
    created: function () {
      const router = this.$router
      router.go({path: '/login'})
    }
  }
</script>

But router.go does not work.

Upvotes: 3

Views: 26364

Answers (2)

Morteza Dana
Morteza Dana

Reputation: 71

Remember that router.go takes a single integer parameter that indicates by how many steps to go forwards or go backwards in the history stack. So to give a path you should use router.push('your_url').

For more information I suggest you read this: Vuerouter

Upvotes: 7

steve
steve

Reputation: 1428

Oh, use router.push('/login') can working fine.

Upvotes: 6

Related Questions