feat: describe how to add route rules

This commit is contained in:
2026-01-29 22:49:34 +08:00
parent c214c11244
commit 9e87842f7e
2 changed files with 9 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import {
createWebHashHistory, createWebHashHistory,
type RouteRecordRaw, type RouteRecordRaw,
} from "vue-router"; } from "vue-router";
import { addRulesForRoutes } from "./rules";
/** /**
* 通过 vite 的 meta.glob 从文件系统读取路由文件 * 通过 vite 的 meta.glob 从文件系统读取路由文件
@@ -49,10 +50,12 @@ function getRoutePathFromFilePath(filePath: string): string {
const routes: RouteRecordRaw[] = generateRoutesFromPages(); const routes: RouteRecordRaw[] = generateRoutesFromPages();
const ruledRoutes = addRulesForRoutes(routes);
// WebHash 使用 /# 开头处理前端页面路由 // WebHash 使用 /# 开头处理前端页面路由
const router = createRouter({ const router = createRouter({
history: createWebHashHistory(), history: createWebHashHistory(),
routes, routes: ruledRoutes,
}); });
export default router; export default router;

View File

@@ -0,0 +1,5 @@
import { type RouteRecordRaw } from "vue-router";
export function addRulesForRoutes(router: RouteRecordRaw) {
return router;
}