启动路由器时出现意外错误:错误:缺少必需的参数"catchAll"



有人知道我为什么收到这个警告吗?

[Vue Router warn]:启动路由器时出现意外错误:错误:缺少必需的参数"catchAll";

router.beforeEach((to, from, next) => {
const isAuthenticated = store.getters['users/isAuthenticated']
if (!isAuthenticated && to.name !== 'Login' && to.name !== 'Registration' && to.name !== '404') {
next({
name: 'Login'
})
} else if (isAuthenticated && store.getters['users/getUserName'] !== to.params.userName)   {
next({
name: '404'
})
} else {
next()
}
})

我看到你在Vuejs.org论坛上发布了同样的问题:

https://forum.vuejs.org/t/unexpected-error-when-starting-the-router-error-missing-required-param-catchall/115388/3

为了完整起见,如果其他人遇到同样的问题(就像我一样(,因为您正在以名称name: '404'的代码导航到路线,所以必须为重复模式添加*

你原来的路由器包罗万象,发布在Vue论坛上:

{
path: '/:catchAll(.*)',
name: '404',
component: () => import(/* webpackChunkName: "404" */'@/views/404')
}

您需要按如下方式使用/:catchAll(.*)*

{
path: '/:catchAll(.*)*',
name: '404',
component: () => import(/* webpackChunkName: "404" */'@/views/404')
}

根据论坛上的答案,请参阅Vue路由器文档中的以下参考页面了解更多信息:

https://next.router.vuejs.org/guide/migration/index.html#removed-星形或全包路线https://next.router.vuejs.org/guide/essentials/dynamic-matching.html#catch-全404-非往返

相关内容

最新更新