{ path: '/home', component: Home }
const routes = [ { path: '/home', component: Home }, { path: '/about', component: About } ]
const router = new VueRouter({ routes // routes: routes 的简写 })
this.$router.push({path:`/user/${userId}`})
这种方式须要在路由中做以下配置浏览器
{ path: '/user/:userId', name: '***', component: *** }
这种接收参数的方式是this.$route.params.userId。函数
this.$router.push({name:'Login',params:{id:'leelei'}}) //不带参数 变成 ip/login
this.$router.push({path:'/login',query:{id:'leelei'}) //带查询参数变成 ip/login?id=leelei //带斜杠/表明从根目录出发,不会嵌套以前的路径
query传参是针对path的,params传参是针对name的。。接收参数的方式都差很少。。this.$route.query.和this.$route.params.post
注意这只是跳转url,跳转到这个url显示什么组件,得配置路由。router跳转和<router-link>标签跳转,规则差很少。this
谢谢你们,若是有错误的地方请指出。url