如何在輸入 http://localhost:8080/、http://localhost:8080/store/、http://localhost:8080/custom-store/ 這三個中任意一個鏈接都能正確跳轉(zhuǎn)到 http://localhost:8080/store/home/index 。要實這個要求,有兩種方式:
- 重定向
const router = new VueRouter({
routes: [
{
path: '/store/home/index',
name: 'index'
},
{
path: '/',
redirect: {
name: 'index'
}
},
{
path: '/store',
redirect: {
name: 'index'
}
},
{
path: '/custom-store',
redirect: {
name: 'index'
}
},
]
})
以下截圖是重定向在項目中實際應(yīng)用:
- 別名
const router = new VueRouter({
routes: [
{
path: '/store/home/index',
name: 'index',
alias: ['/', '/store', '/custom-store']
}
]
})