美文网首页
vue3 中获取当前路由地址避坑——router.current

vue3 中获取当前路由地址避坑——router.current

作者: 缺月楼 | 来源:发表于2022-09-26 23:24 被阅读0次

1.router.currentRoute相当于$route但是$route.path或者$route.fullPath只能在组件中用
组件里头:

/user?a=10` $route.path === /user  $route.fullPath === /user?a=10

js模块中要使用router.currentRoute
js模块中:router.currentRoute.value.fullPath 就是当前路由地址,router.currentRouteref响应式数据 要拿值的话需要.value

2.encodeURIComponent 转换uri编码,防止解析地址出问题 用来解析获得的ullPath中的特殊字符

const fullPath = encodeURIComponent(router.currentRoute.value.fullPath)

相关文章

网友评论

      本文标题:vue3 中获取当前路由地址避坑——router.current

      本文链接:https://www.haomeiwen.com/subject/ixbqartx.html