vue 路由配置

时间:2022-03-27 07:09:52

1.不带参数的路由配置 及 跳转

//路由配置:

{

name: "a",
path: "/a",
component: a
}
 
页面跳转:
this.$router.push('/a');  
this.$router.push({path:'/a'});
this.$router.push({name:'a'})
 
2.带参数的路由配置及页面跳转 和 接收参数

//路由配置:

{

name: "a",
path: "/a/:userid",
component: a
}
//页面跳转:
this.$router.push({name:'a',params:{userid:123}});    接收: this.$route.params.userid
this.$router.push({path:'/a',params:{userid:123}})   错误,如果提供了 pathparams 会被忽略
this.$router.push({path:'/a/123'});                             接收: this.$route.params.userid
 
this.$router.push({path:'/a?userid=123'})  接收:this.$route.query.userid  ----- 这一项的路由配置 path:'/a' ,不用带参数
 this.$router.push({path:'/a',query:{userid:123}})         接收: this.$route.query.userid ----- 这一项的路由配置 path:'/a' ,不用带参数