VueJS路由器中的path和fullPath有什么区别?

Uly*_* BN 5 javascript vue-router vuejs2

在我的router.js文件,当我使用的beforeEach方法,我得到pathfullPath在性能tofrom参数。我想知道我应该使用哪个重定向。我已经看到了两者都被使用过,我什么时候不使用,两者之间有什么区别。

例子:

export default new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [{
        path: 'login'
        beforeEnter: (to, from, next) => {
            console.log(to, from) // the routes
            if (User.loggedIn()) {
                next(from.fullPath) // or maybe `from.path`
            } else {
                next()
            }
        },
    }]
})
Run Code Online (Sandbox Code Playgroud)

小智 6

Vue API参考中

  • $ route.fullPath
    • 类型:string
      完整的解析URL,包括查询和哈希。
  • $ route.path
    • 类型:string
      一个字符串,它等于当前路径的路径,始终解析为绝对路径。例如“ / foo / bar”。