报错的写法
{
path: "*",
redirect: "/404"
}
报错提示
- vue-router.mjs:1326 Uncaught Error: Catch all routes ("*") must now be defined using a param with a custom regexp.
报错信息
解决方法
{
path: "/:notFound(.*)",
redirect: "/404"
}
解决原理
- 通过*来任意匹配的写法已被官网废弃
- 必须通过正则来匹配
- 上述写法是-----> :notFound(.*)
- :表示可选参数
- notFound:表示可选参数名(任意名均可)
- .*:表示正则匹配