2023-02-11 00:44:00 +08:00
|
|
|
|
import type { App } from 'vue'
|
|
|
|
|
import type { RouteRecordRaw } from 'vue-router'
|
2023-04-07 01:45:29 +08:00
|
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
2023-02-11 00:44:00 +08:00
|
|
|
|
import remainingRouter from './modules/remaining'
|
|
|
|
|
|
|
|
|
|
// 创建路由实例
|
|
|
|
|
const router = createRouter({
|
2023-04-07 01:45:29 +08:00
|
|
|
|
history: createWebHistory(), // createWebHashHistory URL带#,createWebHistory URL不带#
|
2023-02-11 00:44:00 +08:00
|
|
|
|
strict: true,
|
|
|
|
|
routes: remainingRouter as RouteRecordRaw[],
|
|
|
|
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const resetRouter = (): void => {
|
|
|
|
|
const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
|
|
|
|
|
router.getRoutes().forEach((route) => {
|
|
|
|
|
const { name } = route
|
|
|
|
|
if (name && !resetWhiteNameList.includes(name as string)) {
|
|
|
|
|
router.hasRoute(name) && router.removeRoute(name)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const setupRouter = (app: App<Element>) => {
|
|
|
|
|
app.use(router)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default router
|