Skip to content

Commit fe609e7

Browse files
committed
fix(routing): adds path match to redirect unknown routes
1 parent 9adf5a7 commit fe609e7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/components/HelloWorld.vue

-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
<script setup lang="ts">
2-
import { watch } from 'vue';
3-
42
const props = defineProps<{
53
msg: string;
64
}>();
7-
8-
watch(
9-
() => props.msg,
10-
_msg => console.info(_msg),
11-
);
125
</script>
136

147
<template>

src/router/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ export const createRouter = ({ baseName = '', baseUrl = import.meta.env.BASE_URL
88
const { setBaseName, setBaseUrl } = useRouterStore();
99
setBaseName(baseName);
1010
setBaseUrl(baseUrl);
11+
const _routes = routes.map(r => ({ ...r, path: `${baseName}${r.path}` }));
1112
return createVueRouter({
1213
history: createWebHashHistory(baseUrl),
13-
routes: routes.map(r => ({ ...r, path: `${baseName}${r.path}` })),
14+
routes: [
15+
{
16+
path: '/:pathMatch(.*)',
17+
redirect: `${baseName}/`,
18+
},
19+
..._routes,
20+
],
1421
});
1522
};

0 commit comments

Comments
 (0)