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",
|
"vue-router": "VueRouter",
|
||||||
},
|
},
|
||||||
exports: "named",
|
exports: "named",
|
||||||
|
generatedCode: "es5",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { Component, Ref } from "vue";
|
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 { MenuGroupType } from "./menus";
|
||||||
import type { PagesPublicState } from "../states/pages";
|
import type { PagesPublicState } from "../states/pages";
|
||||||
|
|
||||||
|
@ -7,6 +7,11 @@ export type ExtensionPointName = "PAGES" | "POSTS";
|
||||||
|
|
||||||
export type ExtensionPointState = PagesPublicState;
|
export type ExtensionPointState = PagesPublicState;
|
||||||
|
|
||||||
|
interface RouteRecordAppend {
|
||||||
|
parentName: RouteRecordName;
|
||||||
|
route: RouteRecordRaw;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Plugin {
|
export interface Plugin {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@ -25,7 +30,7 @@ export interface Plugin {
|
||||||
*/
|
*/
|
||||||
deactivated?: () => void;
|
deactivated?: () => void;
|
||||||
|
|
||||||
routes?: RouteRecordRaw[];
|
routes?: RouteRecordRaw[] | RouteRecordAppend[];
|
||||||
|
|
||||||
menus?: MenuGroupType[];
|
menus?: MenuGroupType[];
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ export default defineConfig({
|
||||||
"@halo-dev/components": "HaloComponents",
|
"@halo-dev/components": "HaloComponents",
|
||||||
},
|
},
|
||||||
exports: "named",
|
exports: "named",
|
||||||
|
generatedCode: "es5",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
|
|
@ -47,7 +47,11 @@ function registerModule(pluginModule: Plugin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const route of pluginModule.routes) {
|
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 { BasicLayout, definePlugin } from "@halo-dev/admin-shared";
|
||||||
import SheetList from "./PageList.vue";
|
import PageList from "./PageList.vue";
|
||||||
import { IconPages } from "@halo-dev/components";
|
import { IconPages } from "@halo-dev/components";
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
|
@ -9,11 +9,12 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
path: "/pages",
|
path: "/pages",
|
||||||
component: BasicLayout,
|
component: BasicLayout,
|
||||||
|
name: "BasePages",
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "",
|
path: "",
|
||||||
name: "Pages",
|
name: "Pages",
|
||||||
component: SheetList,
|
component: PageList,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue