vue-router报错

报错内容:Catch all routes (“*”) must now be defined using a param with a custom regexp.

意思: 捕获所有路由(“”)现在必须使用带有自定义正则表达式的参数来定义。

原因: vue2和vue3的差异。

官网提示: 如果你不打算使用其名称直接跳转到未找到的路由,则无需为重复的参数添加 *。如果你调用 router.push(‘/not/found/url’),它将提供正确的 pathMatch 参数。

解决方法:

{
    
    
     // 识别不到的path 自动调转404
     // vue2使用* vue3使用:pathMatch('*') 或者 :pathMatch('*')* 或者 :catchAll(.*)
    path: "/:catchAll(.*)",
    redirect: '/404',
},

猜你喜欢

转载自blog.csdn.net/qq_45142260/article/details/129085979