bunny-web-template/src/router/index.ts

33 lines
955 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-03-01 20:51:33 +08:00
import error from '@/router/modules/error';
import home from '@/router/modules/home';
import remaining from '@/router/modules/remaining';
2025-02-25 18:29:26 +08:00
// 静态路由
2025-05-15 22:49:56 +08:00
const routes: RouteRecordRaw[] = [...remaining, ...home, ...error] as RouteRecordRaw[];
2025-02-25 18:29:26 +08:00
const router = createRouter({
history: createWebHashHistory(),
routes,
2025-05-15 22:49:56 +08:00
scrollBehavior: () => ({ left: 0, top: 0, behavior: 'smooth' }),
2025-02-25 18:29:26 +08:00
});
/** 全局注册 router */
2025-05-15 22:49:56 +08:00
export const setupRouter = (app: App<Element>) => {
app.use(router);
2025-02-25 18:29:26 +08:00
};
/** 重置路由 */
export const resetRouter = () => {
router.replace({ path: '/' }).then();
2025-02-25 18:29:26 +08:00
};
2025-03-01 20:51:33 +08:00
2025-05-15 22:49:56 +08:00
// router.afterEach((to, from) => {
// const toDepth = to.path.split('/').length;
// const fromDepth = from.path.split('/').length;
// to.meta.transition = toDepth < fromDepth ? 'slide-right' : 'slide-left';
// });
2025-02-25 18:29:26 +08:00
export default router;