版本号:
vue/cli:4.5.12
@vue/cli-plugin-router: ~4.5.0
问题
以下写法会导致报警告:[Vue Router warn]: Path "/" was passed with params but they will be ignored. Use a named route alongside params instead.
[Vue Router 警告]:路径“/”与参数一起传递,但它们将被忽略。改为在 params 旁边使用命名路由
const router = createRouter({
history: createWebHashHistory(),
routes: [{
name: 'Home',
path: '/',
component: () => import( /* webpackChunkName: "home" */ '../views/home/index.vue'),
},{
path: '/:pathMatch(.*)',
redirect: '/'
}]
})
解决方案
const router = createRouter({
history: createWebHashHistory(),
routes: [{
name: 'Home',
path: '/',
component: () => import( /* webpackChunkName: "home" */ '../views/home/index.vue'),
},{
path: '/:pathMatch(.*)',
redirect: {
name: 'Home'
}
}]
})