Skip to content

Commit

Permalink
fix(projects): fix layoutLazyImport
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Aug 23, 2023
1 parent dfa46ef commit dacceab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
26 changes: 9 additions & 17 deletions examples/template-vue/src/router/elegant/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RouteLayout, RouteComponent | (() => Promise<RouteComponent>)> = {
default: DefaultLayout,
default: () => import("@/layouts/default-layout/index.vue"),
};

export const views: Record<LastLevelRouteKey, RouteComponent | (() => Promise<RouteComponent>)> = {
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"),
};
2 changes: 1 addition & 1 deletion examples/template-vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/context/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),`;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dacceab

Please sign in to comment.