Industrial-image-management.../src/router/index.ts

34 lines
970 B
TypeScript
Raw Normal View History

2025-06-27 19:54:42 +08:00
import { createRouter, createWebHistory } from 'vue-router'
import { useRouteStore } from '@/stores'
import { constantRoutes, systemRoutes } from '@/router/route'
import { setupRouterGuard } from '@/router/guard'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [...constantRoutes, ...systemRoutes],
scrollBehavior: () => ({ left: 0, top: 0 }),
})
setupRouterGuard(router)
/**
* @description
* @description name
*/
export function resetRouter() {
try {
const routeStore = useRouteStore()
routeStore.asyncRoutes.forEach((route) => {
const { name } = route
if (name) {
router.hasRoute(name) && router.removeRoute(name)
}
})
} catch (error) {
// 强制刷新浏览器也行,只是交互体验不是很好
window.location.reload()
}
}
export default router