router-link
this.$router.push() (函数里面调用)
this.$router.replace() (用法同push)
this.$router.go(n)
路由配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由跳转
跳转
跳转
路由配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由跳转
this.$router.push('/index')
this.$router.push({name:'index'})
this.$router.push({path:'/index'})
用法和this.$router.push()
一样,push
效果是进行跳转,replace
可以理解为非跳转,而是替换当前路由地址
路由配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由跳转
this.$router.replace('/index')
this.$router.replace({name:'index'})
this.$router.replace({path:'/index'})
向前或者向后跳转n个页面,n可为正整数或负整数
n为正整,则向前跳转
n为负数,则向后跳转
params
传参路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
跳转
路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index/:id',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
跳转
两种方法可取:
html 页面直接使用:$route.params.id
script 取参:this.$route.params.id
Index页面
html 取参:{{$route.params.id}}
script 取参{{linkOne}}
query
传参路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
跳转
两种方法可取:
html 页面直接使用:$route.query.id
script 取参:this.$route.query.id
Index页面
html 取参:{{$route.query.id}}
script 取参{{linkOne}}
params
传参路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
this.$router.push({name:'index',params: {id:'1'}})
路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index/:id',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
this.$router.push({name:'index',params: {id:'1'}})
两种方法可取:
html 页面直接使用:$route.params.id
script 取参:this.$route.params.id
Index页面
html 取参:{{$route.params.id}}
script 取参{{routerData}}
query
传参路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
this.$router.push({name:'index',query: {id:'1'}})
两种方法可取:
html 页面直接使用:$route.query.id
script 取参:this.$route.query.id
Index页面
html 取参:{{$route.query.id}}
script 取参{{routerData}}
用法和this.$router.push()
一样,push
效果是进行跳转,replace
可以理解为非跳转,而是替换当前路由地址
params
传参路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
this.$router.replace({name:'index',params: {id:'1'}})
路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index/:id',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
this.$router.replace({name:'index',params: {id:'1'}})
两种方法可取:
html 页面直接使用:$route.params.id
script 取参:this.$route.params.id
Index页面
html 取参:{{$route.params.id}}
script 取参{{routerData}}
query
传参路由参数配置
{ path: '/home',name: 'home',component: ()=>import('@/components/router/Home.vue') },
{ path: '/index',name: 'index',component: ()=>import('@/components/router/Index.vue') },
路由传值跳转
this.$router.replace({name:'index',query: {id:'1'}})
两种方法可取:
html 页面直接使用:$route.query.id
script 取参:this.$route.query.id
Index页面
html 取参:{{$route.query.id}}
script 取参{{routerData}}