vehicle-monitor/src/router/index.ts

26 lines
662 B
TypeScript
Raw Normal View History

2025-02-25 18:29:26 +08:00
import type { App } from 'vue';
import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router';
2025-02-28 20:14:37 +08:00
import error from '@/router/modules/error';
import remaining from '@/router/modules/remaining';
2025-02-25 18:29:26 +08:00
// 静态路由
const routes: RouteRecordRaw[] = [...remaining, ...error];
2025-02-25 18:29:26 +08:00
const router = createRouter({
2025-02-26 16:31:59 +08:00
history: createWebHashHistory(),
routes,
2025-03-02 22:46:59 +08:00
scrollBehavior: () => ({ left: 0, top: 0, behavior: 'smooth' }),
2025-02-25 18:29:26 +08:00
});
/** 全局注册 router */
2025-03-01 21:32:03 +08:00
export const setupRouter = (app: App<Element>) => {
2025-02-26 16:31:59 +08:00
app.use(router);
2025-02-25 18:29:26 +08:00
};
/** 重置路由 */
export const resetRouter = () => {
2025-02-26 16:31:59 +08:00
router.replace({ path: '/' }).then();
2025-02-25 18:29:26 +08:00
};
2025-03-01 20:52:06 +08:00
2025-02-25 18:29:26 +08:00
export default router;