1.router.currentRoute相當(dāng)于$route但是$route.path或者$route.fullPath只能在組件中用
組件里頭:
/user?a=10` $route.path === /user $route.fullPath === /user?a=10
js模塊中要使用router.currentRoute
js模塊中:router.currentRoute.value.fullPath 就是當(dāng)前路由地址,router.currentRoute是ref響應(yīng)式數(shù)據(jù) 要拿值的話需要.value
2.encodeURIComponent 轉(zhuǎn)換uri編碼,防止解析地址出問題 用來解析獲得的ullPath中的特殊字符
const fullPath = encodeURIComponent(router.currentRoute.value.fullPath)