Vue-路由跳转的几种方式和路由重定向
Posted yangchin9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vue-路由跳转的几种方式和路由重定向相关的知识,希望对你有一定的参考价值。
一、标签路由 router-link
注意:router-link中链接如果是‘/‘开始就是从根路由开始,如果开始不带‘/‘,则从当前路由开始。
1、不传参 <router-link :to="name:‘Home‘"> <router-link :to="path:‘/home‘"> 2、传参 <router-link :to="name:‘Home‘, params: id:1"> <router-link :to="path:‘/home‘, params: id:1"> // params传参数 // 路由配置 path: "/home/:id" // 不配置path ,第一次可请求,刷新页面id会消失 // 配置path,刷新页面id会保留 // html 取参 $route.params.id // script 取参 this.$route.params.id <router-link :to="name:‘Home‘, query: id:1">
// query传参数 (类似get,页面url后面会显示参数) // 路由可不配置 // html 取参 $route.query.id // script 取参 this.$route.query.id
二、编程式路由 this.$router.push()
1、不传参 this.$router.push(‘/home‘) this.$router.push(name:‘Home‘) this.$router.push(path:‘/home‘) 2、传参 this.$router.push(name:‘home‘,params: id:‘1‘) // 只能用 name // params传参数 // 路由配置 path: "/home/:id" // 不配置path ,第一次可请求,刷新页面id会消失 // 配置path,刷新页面id会保留 // html 取参 $route.params.id // script 取参 this.$route.params.id this.$router.push(name:‘Home‘,query: id:‘1‘) this.$router.push(path:‘/home‘,query: id:‘1‘) // query传参数 (类似get,页面url后面会显示参数) // 路由可不配置 // html 取参 $route.query.id // script 取参 this.$route.query.id
以上是关于Vue-路由跳转的几种方式和路由重定向的主要内容,如果未能解决你的问题,请参考以下文章