mirror of https://github.com/halo-dev/halo-admin
feat: support for dynamically adding child routes to a route
Signed-off-by: Ryan Wang <i@ryanc.cc>pull/596/head
parent
325a64546d
commit
7c3692c5ed
|
@ -39,6 +39,7 @@ export default defineConfig({
|
|||
"vue-router": "VueRouter",
|
||||
},
|
||||
exports: "named",
|
||||
generatedCode: "es5",
|
||||
},
|
||||
},
|
||||
sourcemap: true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { Component, Ref } from "vue";
|
||||
import type { RouteRecordRaw } from "vue-router";
|
||||
import type { RouteRecordRaw, RouteRecordName } from "vue-router";
|
||||
import type { MenuGroupType } from "./menus";
|
||||
import type { PagesPublicState } from "../states/pages";
|
||||
|
||||
|
@ -7,6 +7,11 @@ export type ExtensionPointName = "PAGES" | "POSTS";
|
|||
|
||||
export type ExtensionPointState = PagesPublicState;
|
||||
|
||||
interface RouteRecordAppend {
|
||||
parentName: RouteRecordName;
|
||||
route: RouteRecordRaw;
|
||||
}
|
||||
|
||||
export interface Plugin {
|
||||
name: string;
|
||||
|
||||
|
@ -25,7 +30,7 @@ export interface Plugin {
|
|||
*/
|
||||
deactivated?: () => void;
|
||||
|
||||
routes?: RouteRecordRaw[];
|
||||
routes?: RouteRecordRaw[] | RouteRecordAppend[];
|
||||
|
||||
menus?: MenuGroupType[];
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ export default defineConfig({
|
|||
"@halo-dev/components": "HaloComponents",
|
||||
},
|
||||
exports: "named",
|
||||
generatedCode: "es5",
|
||||
},
|
||||
},
|
||||
sourcemap: true,
|
||||
|
|
|
@ -47,7 +47,11 @@ function registerModule(pluginModule: Plugin) {
|
|||
}
|
||||
|
||||
for (const route of pluginModule.routes) {
|
||||
router.addRoute(route);
|
||||
if ("parentName" in route) {
|
||||
router.addRoute(route.parentName, route.route);
|
||||
} else {
|
||||
router.addRoute(route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BasicLayout, definePlugin } from "@halo-dev/admin-shared";
|
||||
import SheetList from "./PageList.vue";
|
||||
import PageList from "./PageList.vue";
|
||||
import { IconPages } from "@halo-dev/components";
|
||||
|
||||
export default definePlugin({
|
||||
|
@ -9,11 +9,12 @@ export default definePlugin({
|
|||
{
|
||||
path: "/pages",
|
||||
component: BasicLayout,
|
||||
name: "BasePages",
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "Pages",
|
||||
component: SheetList,
|
||||
component: PageList,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue