44 lines
1.0 KiB
TypeScript
Executable File
44 lines
1.0 KiB
TypeScript
Executable File
import {
|
|
createMemoryHistory, createRouter, createWebHashHistory, createWebHistory,
|
|
} from 'vue-router'
|
|
|
|
import { cfgrouter } from './route-config'
|
|
import { useGlobalStore } from '@src/store/globalStore';
|
|
|
|
export default function (/* { store, ssrContext } */) {
|
|
const routermode = process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory
|
|
|
|
const createHistory = process.env.SERVER
|
|
? createMemoryHistory
|
|
: routermode
|
|
|
|
const router = createRouter({
|
|
scrollBehavior: () => ({ left: 0, top: 0 }),
|
|
routes: cfgrouter.getmenu(),
|
|
history: createHistory(
|
|
process.env.MODE === 'ssr' ? void 0 : process.env.VUE_ROUTER_BASE,
|
|
),
|
|
});
|
|
|
|
// Add the beforeEach hook
|
|
router.beforeEach((to, from, next) => {
|
|
// Execute your command before each navigation
|
|
// executeCommand();
|
|
|
|
const globalStore = useGlobalStore()
|
|
try {
|
|
globalStore.editOn = false
|
|
} catch(e) {
|
|
|
|
}
|
|
|
|
|
|
// Continue with the navigation
|
|
next();
|
|
});
|
|
|
|
return router;
|
|
}
|
|
|
|
|