1、编程式导航router.push
2、声明式的导航 <router-link>
编程式导航传递参数有两种类型:字符串、对象
字符串:
this.$router.push("home");
对象:
this.$router.push({ name: 'news', params: { userId: 123 }})
//获取:this.$route.params.userId
查询参数其实就是在路由地址后面带上参数和传统的url参数一致,传递参数使用query
而且必须配合path
来传递参数而不能用name
,目标页面接收传递的参数使用query
。
this.$router.push({ path: '/news', query: { userId: 123 }});
//获取:this.$route.query.userId
声明式导航
字符串
<router-link to="news">click to news page</router-link>
命名路由
<router-link :to="{ name: 'news', params: { userId: 1111}}">click to news page</router-link>
查询参数
<router-link :to="{ path: '/news', query: { userId: 1111}}">click to news page</router-link>