在Vue中可以設置路由的重定向,用法如下:
1.redirect: '/path'涛酗、redirect:{}:
this.$routes 和 this.$route區(qū)別:8.Vue路由(路由配置渡贾、傳參碍扔、獲取參數(shù))
案例:
exprot default new Router({
routes: [
{
path: '/',
//redirect: '/RouterB',
redirect: {name: 'RouterB', params: {id:'0001', title:'0002'}}
}
]
});
2.使用 *通配符狠轻,表示沒有匹配使用該路由規(guī)則匹配乳愉,這個建議寫在路由規(guī)則最下面:
案例
import notFound from '../page/notFound/notFound'
exprot default new Router({
routes:[
{
.....
},
//最后使用*通配符逛球,表示以上規(guī)則不滿足則進行該規(guī)則(比如未發(fā)現(xiàn)等)
{
path: '*',
component: notFound
}
]
});
3. notFound.vue
<template>
<div>
頁面飛到外太空去了....
</div>
</template>
<script>
export default {
}
</script>