feat: describe how to add route rules
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
5
src/router/rules/index.ts
Normal file
5
src/router/rules/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { type RouteRecordRaw } from "vue-router";
|
||||||
|
|
||||||
|
export function addRulesForRoutes(router: RouteRecordRaw) {
|
||||||
|
return router;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user