在Vue中可以设置路由的重定向,用法如下:
1.redirect: '/path'、redirect:{}:
this.$routes 和 this.$route区别:8.Vue路由(路由配置、传参、获取参数)
案例:
exprot default new Router({
routes: [
{
path: '/',
//redirect: '/RouterB',
redirect: {name: 'RouterB', params: {id:'0001', title:'0002'}}
}
]
});
2.使用 *通配符,表示没有匹配使用该路由规则匹配,这个建议写在路由规则最下面:
案例
import notFound from '../page/notFound/notFound'
exprot default new Router({
routes:[
{
.....
},
//最后使用*通配符,表示以上规则不满足则进行该规则(比如未发现等)
{
path: '*',
component: notFound
}
]
});
3. notFound.vue
<template>
<div>
页面飞到外太空去了....
</div>
</template>
<script>
export default {
}
</script>
