Vue-router: 关于fullPath,快速获取当前路径

Created on 19 Apr 2016  ·  5Comments  ·  Source: vuejs/vue-router

之前可以获取当前路径(有多个路由共享一个视图组件时),改变query来刷新当前页面数据:

// modify query
newQuery.page = 2
this.$router.go({
  path: this.$route.fullPath,
  query: newQuery
})

现在this.$route.fullPath 在 772d5d0fcfef15dc40123ca0ce9422e2eb4dc3a5 里被去掉了,fullPath只能通过遍历matched获取了。
这里去掉fullPath暴露是出于什么考虑呢?
或者有没有其他获取当前路径的方法?
谢谢。

Most helpful comment

@yyx990803 fullPath的确有用的,有时候我们菜单高亮需要匹配这个字段。
如:
路由是:/path/:type
真正路径:/path/list (此时path为/path/list,而fullPath为/path/:type)
这样匹配路由时比较费力。
希望打开fullPath.

谢谢

All 5 comments

现在Route对象里貌似用path代替了原来fullPath的作用

path和以前一样,是有query部分的。

以后会支持直接 router.go({ query: ... }),也就不需要自己获取 fullPath 了。

@yyx990803 fullPath是有用的,有时候我们需要对比当前是否处于某个路由上,现在没有什么好的办法去进行比较了

@yyx990803 fullPath的确有用的,有时候我们菜单高亮需要匹配这个字段。
如:
路由是:/path/:type
真正路径:/path/list (此时path为/path/list,而fullPath为/path/:type)
这样匹配路由时比较费力。
希望打开fullPath.

谢谢

Was this page helpful?
0 / 5 - 0 ratings