- alias 為路由別名,當在地址欄的文件路徑輸入路由別名時,將跳轉到對應的文件路徑,但不會文件路徑的名字不會改變
- 注意:雖然通過路由別名可以訪問到對應的文件路徑,但是因為router-link設置的地址是'/home',所以觸發不了對應的css
image.png
image.png
- redirect為重定向,可以設置為字符串和對象、函數,當設置函數時可以動態指定重定向目標
export default new Router({
mode: 'history',
linkActiveClass: 'is-active',
routes: [
{
path: '/home',
name: 'home',
component: home,
alias: '/index'
}
{
path: '*',
// component: notfound
// redirect: '/home'
// redirect: {path: '/about'}
// redirect: {name: 'document'}
redirect: (to) => { //動態設置重定向的目標
// 目標路由對象
// console.log(to)
if(to.path === '/123'){
return '/home'
}else if(to.path === '/456'){
return {path: '/about'}
}else{
return {name: 'document'}
}
}
}
]
})