diff --git a/examples/template-vue/src/router/elegant/imports.ts b/examples/template-vue/src/router/elegant/imports.ts index e3f611a..31e039c 100644 --- a/examples/template-vue/src/router/elegant/imports.ts +++ b/examples/template-vue/src/router/elegant/imports.ts @@ -2,29 +2,21 @@ /* prettier-ignore */ // Generated by elegant-router // Read more: https://github.com/soybeanjs/elegant-router + import type { RouteComponent } from "vue-router"; import type { LastLevelRouteKey, RouteLayout } from "@elegant-router/types"; -import DefaultLayout from "@/layouts/default-layout/index.vue"; - -import _403 from "@/views/403/index.vue"; -import _404 from "@/views/404/index.vue"; -import _500 from "@/views/500/index.vue"; -import demoA_child1 from "@/views/demo-a/child1/index.vue"; -import demoA_child2_child3 from "@/views/demo-a/child2/child3/index.vue"; -import demoA_child3 from "@/views/demo-a/child3/index.vue"; -import demo3 from "@/views/demo3/[id].vue"; export const layouts: Record Promise)> = { - default: DefaultLayout, + default: () => import("@/layouts/default-layout/index.vue"), }; export const views: Record Promise)> = { - 403: _403, - 404: _404, - 500: _500, - "demo-a_child1": demoA_child1, - "demo-a_child2_child3": demoA_child2_child3, - "demo-a_child3": demoA_child3, - demo3, + 403: () => import("@/views/403/index.vue"), + 404: () => import("@/views/404/index.vue"), + 500: () => import("@/views/500/index.vue"), + "demo-a_child1": () => import("@/views/demo-a/child1/index.vue"), + "demo-a_child2_child3": () => import("@/views/demo-a/child2/child3/index.vue"), + "demo-a_child3": () => import("@/views/demo-a/child3/index.vue"), + demo3: () => import("@/views/demo3/[id].vue"), }; diff --git a/examples/template-vue/vite.config.ts b/examples/template-vue/vite.config.ts index 58a6358..c2fcd3f 100644 --- a/examples/template-vue/vite.config.ts +++ b/examples/template-vue/vite.config.ts @@ -6,7 +6,7 @@ import Inspect from 'vite-plugin-inspect'; import ElegantVueRouter from '@elegant-router/vue/vite'; export default defineConfig({ - plugins: [vue(), vueJsx(), ElegantVueRouter({ lazyImport: () => false }), Inspect()], + plugins: [vue(), vueJsx(), ElegantVueRouter(), Inspect()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) diff --git a/packages/vue/src/context/imports.ts b/packages/vue/src/context/imports.ts index 02795ea..d06df64 100644 --- a/packages/vue/src/context/imports.ts +++ b/packages/vue/src/context/imports.ts @@ -23,7 +23,7 @@ import type { LastLevelRouteKey, RouteLayout } from "@elegant-router/types"; layoutFiles.forEach(file => { const { layoutName, importPath } = file; - const isLazy = options.lazyImport(layoutName); + const isLazy = options.layoutLazyImport(layoutName); if (isLazy) { exportLayoutCode += `\n ${layoutName}: () => import("${importPath}"),`; @@ -56,7 +56,7 @@ import type { LastLevelRouteKey, RouteLayout } from "@elegant-router/types"; exportCode += '\n};\n'; - return `${preCode + importCode}\n${exportLayoutCode}\n${exportCode}`; + return `${preCode}\n${importCode}${exportLayoutCode}\n${exportCode}`; } function getImportKey(name: string) {