Vue.js redirection to another page

前端 未结 1 445
鱼传尺愫
鱼传尺愫 2020-12-12 13:09

I\'d like to make a redirection in Vue.js similar to the vanilla javascript

window.location.href = \'some_url\'

How could I ac

相关标签:
1条回答
  • 2020-12-12 13:25

    If you are using vue-router, you should use router.go(path) to navigate to any particular route. The router can be accessed from within a component using this.$router.

    Otherwise, window.location.href = 'some url'; works fine for non single-page apps.

    EDIT: router.go() changed in VueJS 2.0. You can use router.push({ name: "yourroutename"}) or just router.push("yourroutename") now to redirect.

    Documentation

    P.S: In controllers use: this.$router.push({ name: 'routename' })

    0 讨论(0)
提交回复
热议问题