feat: support for dynamically adding child routes to a route

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/596/head
Ryan Wang 2022-08-09 12:05:40 +08:00
parent 325a64546d
commit 7c3692c5ed
5 changed files with 17 additions and 5 deletions

View File

@ -39,6 +39,7 @@ export default defineConfig({
"vue-router": "VueRouter",
},
exports: "named",
generatedCode: "es5",
},
},
sourcemap: true,

View File

@ -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[];

View File

@ -38,6 +38,7 @@ export default defineConfig({
"@halo-dev/components": "HaloComponents",
},
exports: "named",
generatedCode: "es5",
},
},
sourcemap: true,

View File

@ -47,9 +47,13 @@ function registerModule(pluginModule: Plugin) {
}
for (const route of pluginModule.routes) {
if ("parentName" in route) {
router.addRoute(route.parentName, route.route);
} else {
router.addRoute(route);
}
}
}
if (pluginModule.menus) {
if (!Array.isArray(pluginModule.menus)) {

View File

@ -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,
},
],
},