vue路由跳转的多种方式

1.router-link to 跳转

<router-link to="/child"><button>跳转</button></router-link>

2.this.$router.push("ComponentName") ,通过路由名称跳转

<button @click="go()">跳转</button>
 go(){
        this.$router.push("Child");
      },

3.this.$router.push({path:"/child"}) ,通过路由的path跳转

<button @click="go2()">跳转</button>
 go2(){
          this.$router.push({path:"/child"});
      },

4.带参数跳转 this.$router.push({path:"/child",params:{test:123}})

<button @click="go3()">带参数跳转</button>
 go3(){
          this.$router.push({path:"/child?test=123"})
      },

这种跳转的路由地址和参数是这样的,用问号拼接的,

获取路由参数,this.$route.query.paramsName

<button @click="getParams()">获取路由参数</button>
 getParams(){
          console.log(this.$route.query.test); // 123
      }

5.跳转到上一个路由,this.$router.go(-1)

<button @click="goback()">返回上一页</button>
 goback(){
          this.$router.go(-1);
      }

6.命名路由的跳转,需要在配置路由上带上参数,<router-link :to={name:‘ComponentName‘,params:{test:123}}></router-link>

  {
      name:"Children",
      path:"/children/:test",
      component:Children
    }
<router-link :to="{name:‘Children‘,params:{test:123}}"><button>跳转带参数</button></router-link>

这种跳转的路由地址和参数是这样的,用 / 拼接的,

获取路由参数:this.$route.params.xxx

<button @click="getParams()">获取路由参数</button>
 getParams(){
         console.log( this.$route.params.test);
      }

原文地址:https://www.cnblogs.com/luguankun/p/10289038.html

时间: 2024-08-29 13:41:55

vue路由跳转的多种方式的相关文章

详解vue 路由跳转四种方式 (带参数)

详解vue 路由跳转四种方式 (带参数):https://www.jb51.net/article/160401.htm 1.  router-link ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1. 不带参数  <router-link :to="{name:'home'}"> <router-link :to="{path:'/home'}"> //name,path都行, 建议用name /

vue路由跳转的方式

vue路由跳转有四种方式 1. router-link 2. this.$router.push() (函数里面调用) 3. this.$router.replace() (用法同push) 4. this.$router.go(n) 一.不带参 1.1 router-link <router-link :to="{name:'home'}"> <router-link :to="{path:'/home'}"> //name,path都行,

2种方式解决vue路由跳转未匹配相应路由避免出现空白页面或者指定404页面

https://www.cnblogs.com/goloving/p/9254084.html https://www.cnblogs.com/goloving/p/9254084.html 1.路由全局守卫 在做项目的时候,遇到需要做路由跳转,但当用户输入错误url地址,或是其它非法url路由地址,我们或许会想到跳转至404页面.不管你有没有写一个404页面,当出现未匹配路由都需重新指定页面跳转.可能大家首先想到会是路由重定向,redirect来解决这个问题.但实际上通过redirect是没办

vue路由跳转时判断用户是否登录功能

通过判断该用户是否登录过,如果没有登录则跳转到login登录路由,如果登录则正常跳转. 一丶首先在用户登录前后分别给出一个状态来标识此用户是否登录(建议用vuex): 简单用vuex表示一下,不会可以自己去官网多看看: import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex); var state = { isLogin:0, //初始时候给一个 isLogin=0 表示用户未登录 }; const mutations = { cha

Vue路由跳转问题记录

最近项目上需要用Vue用来做app,在Vue中使用路由时遇到下面的问题. 路由设置如下: { path:'/tab', component:Tab, children:[{ path:'layoutList', name:'LayoutList', component:LayoutList },{ path:'layoutView/:layoutId', name:'LayoutView', component:LayoutView },{ path:'layoutDetail/:viewId'

vue 路由跳转出现的问题

在 export defaul new Router({ )} 这个路由配置中一定要加mode : 'history' 否者就会在路由前面默认添加# 路由跳转的几种方式: 原文地址:https://www.cnblogs.com/lzzey/p/8461214.html

Vue路由跳转

路由跳转 this.$router.push('/course'); this.$router.push({name:'course'}) this.$router.go(-1) // js逻辑使用history,完成返回上一页 this.$router.go(1) // 前进一页 <router-link to="/course">课程页</router-link> <router-link :to="{name:'course'}"

React路由安装使用和多种方式传参

安装路由 npm i react-router-dom -S 引入路由 import { BowserRouter as Router, Route, Switch, ... } from "react-router-dom" 整个项目顶层需要用<Router>包裹 并且 <Router>组件内只能有一个直接子级元素 例如: let App = props => (<Router> <div> <Route path=&quo

VUE学习--路由跳转方式||路由跳转携带参数方式||目标路由接受参数方式

跳转方式1:.使用便签跳转, <router-link to="{path:'路由地址',params:{传的数据},query:{传的参数}" >:跳转方式2:导航跳转,{在路由内 (路由对象) router.push({ path:'路径',//具有导航功能 name:‘路由名称’,,//同样具有导航功能 params:{传的数据}, query:{传的参数}"});在组件内 (路由对象)this.$router.push(参数同上); 传参方式1:query