|
|
@@ -0,0 +1,24 @@
|
|
|
+const modules = import.meta.glob('../views/**/*.vue')
|
|
|
+
|
|
|
+const dynamicImport = (modules: any, component: string) => {
|
|
|
+ const keys = Object.keys(modules)
|
|
|
+ const matchKey = keys.find(key => {
|
|
|
+ const k = key.replace('../views/', '')
|
|
|
+ return k === component
|
|
|
+ })
|
|
|
+ return matchKey && modules[matchKey]
|
|
|
+}
|
|
|
+
|
|
|
+export const generatorDynamicRouter = (dynamicRouter: Array<any>) => {
|
|
|
+ dynamicRouter.forEach((item: any) => {
|
|
|
+ if (item.component) {
|
|
|
+ item.component = dynamicImport(modules, item.component)
|
|
|
+ } else {
|
|
|
+ delete item['component']
|
|
|
+ }
|
|
|
+ if (item.children) {
|
|
|
+ generatorDynamicRouter(item.children)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return dynamicRouter
|
|
|
+}
|