javascript-VueJS路由器中的path和fullPath有什么区别?
作者:互联网
在我的router.js文件中,当我使用beforeEach方法时,我在to和from参数的属性中获得path和fullPath.我想知道我应该使用哪个重定向.我已经看到了两者都被使用过,我什么时候不使用,两者之间有什么区别.
一个例子:
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()
}
},
}]
})
解决方法:
- $route.fullPath
- type:
string
The full resolved URL including query and hash.- $route.path
- type:
string
A string that equals the path of the current route, always resolved as an absolute path. e.g. “/foo/bar”.
标签:vue-router,vuejs2,javascript 来源: https://codeday.me/bug/20191108/2007861.html