2023-06-07 04:23:20 +00:00
|
|
|
import { type RouteRecordRaw, createWebHistory, createRouter } from 'vue-router'
|
|
|
|
import { constantRoutes, WHITE_LIST } from './router'
|
2023-05-28 17:16:19 +00:00
|
|
|
import { asyncRoutes } from './router'
|
2023-04-20 08:04:08 +00:00
|
|
|
|
|
|
|
const router = createRouter({
|
2023-05-28 17:16:19 +00:00
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
2023-06-07 04:23:20 +00:00
|
|
|
routes: [...constantRoutes, ...asyncRoutes] as RouteRecordRaw[],
|
2023-09-07 13:37:40 +00:00
|
|
|
scrollBehavior(to, from, savedPosition) {
|
|
|
|
if (savedPosition) {
|
|
|
|
return savedPosition
|
|
|
|
} else {
|
|
|
|
return { top: 0, behavior: 'smooth' }
|
|
|
|
}
|
|
|
|
},
|
2023-05-02 18:20:22 +00:00
|
|
|
})
|
2023-04-20 08:04:08 +00:00
|
|
|
|
|
|
|
export function resetRouter() {
|
2023-05-28 17:16:19 +00:00
|
|
|
router.getRoutes().forEach((route) => {
|
|
|
|
const { name } = route
|
|
|
|
if (name && !WHITE_LIST.includes(name as string)) {
|
|
|
|
router.hasRoute(name) && router.removeRoute(name)
|
|
|
|
}
|
|
|
|
})
|
2023-04-20 08:04:08 +00:00
|
|
|
}
|
|
|
|
|
2023-05-02 18:20:22 +00:00
|
|
|
export default router
|