[Vue] vue-router 404 페이지
[Vue] vue-router 404 페이지
/:anyting(.*) 404페이지
정규식 문법을 이용하여 아무 문자나 입력했을때는 404 페이지를 보여줄 수 있다.
이때 순서가 중요하다, 가장 하단에 배치하는 것이 좋다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(router.js)
import { createWebHistory, createRouter } from "vue-router";
// vue-router 라이브러리의 함수들을 import 한다.
// createRouter : 라우터생성을 도와주는 함수
import comp404 from './components/comp404.vue';
const routes = [
{
path: "/:anything(.*)", // 404페이지
component: comp404,
}
];
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;
This post is licensed under CC BY 4.0 by the author.