每天一点点之vue框架开发 - vue-router路由进阶(路由别名、跳转、设置默认路由)

路由别名
 
在main.js中的路由中添加name来创建别名
const routes = [
    {path:'/footer',name:footerLink,component:Footer}
]

在组件中的路由中通过对象属性来实现路由

<router-link :to="{name:homeLink}">Mirror微申</router-link>
跳转
 
1.跳转到上一次浏览的页面
this.$router.go(-1)
2.跳转到指定路由
this.$router.replace(‘/footer’)
// 还可以通过别名跳转
this.$router.replace({name:’footerLink’})
 
也可以通过push进行
this.$router.push(‘/footer’)
this.$router.push({name:’footerLink’})
 
设置默认路由
 
const routes = [
    {path:'/',redirect:'/home'},
    {path:'/home',name:homeLink,component:Home},
]
 
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/cap-rq/p/10101237.html