Skip to content

Commit

Permalink
fix(projects): fix default layout option
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Sep 1, 2023
1 parent 99a3742 commit 8066035
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 3 additions & 6 deletions packages/vue/src/context/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { writeFile } from 'node:fs/promises';
import type { ElegantRouterFile } from '@elegant-router/core';
import type { ElegantVueRouterOption, LayoutFile } from '../types';
import { ensureFile } from '../shared/fs';
import { createPrefixCommentOfGenFile } from './comment';

function getImportsCode(files: ElegantRouterFile[], options: ElegantVueRouterOption) {
const layoutFiles = getLayoutFile(options);

const preCode = `/* eslint-disable */
/* prettier-ignore */
// Generated by elegant-router
// Read more: https://github.com/soybeanjs/elegant-router
`;
const preCode = createPrefixCommentOfGenFile();

let importCode = `import type { RouteComponent } from "vue-router";
import type { LastLevelRouteKey, RouteLayout } from "@elegant-router/types";
Expand Down Expand Up @@ -56,7 +53,7 @@ import type { LastLevelRouteKey, RouteLayout } from "@elegant-router/types";

exportCode += '\n};\n';

return `${preCode}\n${importCode}${exportLayoutCode}\n${exportCode}`;
return `${preCode}\n\n${importCode}${exportLayoutCode}\n${exportCode}`;
}

function getImportKey(name: string) {
Expand Down
4 changes: 3 additions & 1 deletion packages/vue/src/context/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createPluginOptions(erOptions: ElegantRouterOption, options?: Pa
'not-found': '/:pathMatch(.*)*'
};
const DEFAULT_LAYOUTS: Record<string, string> = {
default: 'src/layouts/default-layout/index.vue'
base: 'src/layouts/base-layout/index.vue'
};

const opts: ElegantVueRouterOption = {
Expand All @@ -34,5 +34,7 @@ export function createPluginOptions(erOptions: ElegantRouterOption, options?: Pa
...options
};

opts.defaultLayout = Object.keys(opts.layouts)[0];

return opts;
}
2 changes: 1 addition & 1 deletion packages/vue/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ElegantVueRouterOption extends ElegantRouterOption {
* @default
* ```ts
* const layouts: Record<string, string> = {
* default: 'src/layouts/default-layout/index.vue'
* base: 'src/layouts/base-layout/index.vue'
* }
* ```
*/
Expand Down

0 comments on commit 8066035

Please sign in to comment.