-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
37 lines (29 loc) · 1.04 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { createRouter, createWebHistory, useRoute } from 'vue-router';
import routesConfig from '@xaxay/portal/config/routes';
const routeEntries = Object.entries(routesConfig);
const currentPath = window.location.pathname;
let BASE_URL = currentPath.substring(0, currentPath.length-1);
console.log('BASE_URL', BASE_URL);
// Define routes
const routes = [
...routeEntries.map(([path, data]) => ({
path: `${path}`,
component: () => import(data.module),
meta: { title: data.title }
}))
];
console.log('dynamic routes:', routes);
const defaultRouteEntry = routeEntries.find(([_routePath, routeData]) => routeData.default);
if (defaultRouteEntry) {
const [defaultRoutePath] = defaultRouteEntry;
console.log('default route:', defaultRoutePath);
routes.unshift({ path: '/', redirect: defaultRoutePath });
}
export const router = createRouter({
history: createWebHistory(BASE_URL),
routes
});
router.beforeEach((to, from, next) => {
console.log('[router]', 'to', to?.path, 'from', from?.path)
next();
});