@[TOC] (vue3) catch all routes (“*”) must now be defined using a param with a custom regexp.)
Background
When the vue3 project specifies an unrecognized path to automatically jump to the 404 page when configuring the route, it reports an error catch all routes (“*”) must now be defined using a param with a custom regexp. </ font>
this means that all routes (“) must now be defined with a parameter with a self-defined regular expression
Solution
Change to the following configuration mode:
{
path: "/:catchAll(.*)", // Unrecognized path automatically matches 404
redirect: '/404',
},
Full routing configuration:
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Index',
component: () => import('@/views/Index/Index.vue'),
},
// {
// path: '/', // Root directory auto-match/home
// redirect: '/index',
// },
{
path: '/404',
name: 'PageNotExist',
component: () => import('@/views/PageNotExist/PageNotExist.vue'),
},
{
path: "/:catchAll(.*)", // Unrecognized path automatically matches 404
redirect: '/404',
},
];
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
});
export default router;
Read More:
- Solving routing errors by rewriting Vue push method
- Vue wran name Error: Unkown custom element [How to Solve]
- How to Solve “Vue is not defined” Error
- [Solved] vite2+vue3 jsx Error: React is not defined
- The solution to the problem that the custom styles of UI components such as element-ui in the vue project do not take effect
- [Solved] Vue eslint Error: Component name “*****“ should always be multi-word
- [Solved] Vue item error: Regeneratorruntime is not defined
- JS uses onerror to automatically catch exceptions
- [Solved] Vue Error: template or render function not defined
- Ant design vue table Error: h is not defined [How to Solve]
- vue eslint error ‘process‘ is not defined no-undef [How to Solve]
- [Solved] Vue 3 Script Setup ESLint Error: ‘defineProps‘ is not defined
- Vue3.0 error: Failed to resolve component el-form-item (el element to be unable to be displayed)
- [Solved] Vue Project startup error: no eslint configuration found
- [Solved] Vue Error: error ‘xxx‘ is defined but never used no-unused-vars
- vue error: ‘ev’ is defined but never used (no-unused-vars)
- Vue warn]: vue3 element Component emit Pass Event Error
- How to Solve Vue cli configuration SCSS global variable error
- [Solved] Front end error: Unknown custom element
- [Solved] Vue3 process Error: Uncaught ReferenceError: process is not defined