vue-router路由信息对象属性

18 篇文章 4 订阅

vue路由信息xi对象为this.$route,下面详细列一下该对象属性的详细信息

 

属性名类型读写说明
$route.pathstaring只读

当前路由的名字(一般为#后面的部分,但不包含query查询值)

如:http://example.com/#/login?name=aa

this.$route.path;    //输出“/login”

$route.queryobject只读

可访问携带的查询参数

如:this.$router.push({name: 'login', query:{name: 'you'}})

此时路由为:http://example.com/#/login?name=you

可直接访问this.$route.query.name;    //you

$route.paramsobject只读

路由转跳携带参数

如:this.$route.push({name: 'hello', params: {name: 'you'})

此时可访问this.$route.params.name;    //you

$route.hashstring只读当前路径的哈希值,带#
$route.fullPathstring只读

完整的路径值

如:http://example.com/#/login?name=aa

this.$toute.fullPath;    //输出“/login?name=aa”

$route.namestring只读命名路由的
$route.matchedarray只读

当前路由下路由声明的所有信息,从父路由(如果有)到当前路由为止

$route.redirectedFromstring只读

重定向来源

如:{ path: '*',redirect: {name: 'hello'}}

此时访问不存在的路由http://example.com/#/a会重定向到hello

在hello访问this.$route.redirectedFrom;    //输出“/a”

以上是路由对象的常见属性,基本的信息都涵盖了,且亲测

有新的再补充吧!

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值