javascript - VueJS路由器中的`path`和`fullPath`有什么区别?
问题描述
在我的router.js
文件中,当我使用该beforeEach
方法时,我会在和参数的属性中获取path
和。我想知道我应该使用哪一个来进行重定向。我已经看到两者都被使用了,但我不知道何时使用哪个,两者之间有什么区别。fullPath
to
from
一个例子:
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()
}
},
}]
})
解决方案
来自Vue API 参考:
- $route.fullPath
- type:
string
完整解析的 URL,包括查询和哈希。- $route.path
- type:
string
一个字符串,等于当前路由的路径,总是解析为绝对路径。例如“/foo/bar”。
推荐阅读
- konvajs - 绘制矩形不能遮蔽我的图像
- web-services - Spring 集成 web 服务 jms
- sql - 获取表中下一行的值总和
- java - Java 8:如何转换列表
- javascript - 在提交表单时调用 Javascript 函数
- angularjs - 如何在Angularjs中动态设置方法名称
- less - Unitize mixin 为 px 和 rem 生成 css 代码
- javascript - PushNotification 未定义错误
- haskell - Haskell中荒谬的函数定义中的seq有什么意义
- android - 在 Recycler View 的 Image 视图右侧显示 Custom Toast