最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why the router.go() does not work in Vue Router? - Stack Overflow

programmeradmin12浏览0评论

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.

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.

Share Improve this question edited Dec 25, 2021 at 2:19 Penny Liu 17.4k5 gold badges86 silver badges108 bronze badges asked Dec 9, 2016 at 16:52 stevesteve 1,4185 gold badges17 silver badges26 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 7

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

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

发布评论

评论列表(0)

  1. 暂无评论