mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 03:25:24 +00:00
skip layout components where none is provided - fixes #312
This commit is contained in:
@@ -79,6 +79,8 @@ function generate_client(
|
||||
pattern: ${page.pattern},
|
||||
parts: [
|
||||
${page.parts.map(part => {
|
||||
if (part === null) return 'null';
|
||||
|
||||
if (part.params.length > 0) {
|
||||
const props = part.params.map((param, i) => `${param}: match[${i + 1}]`);
|
||||
return `{ component: ${part.component.name}, params: match => ({ ${props.join(', ')} }) }`;
|
||||
@@ -150,6 +152,8 @@ function generate_server(
|
||||
pattern: ${page.pattern},
|
||||
parts: [
|
||||
${page.parts.map(part => {
|
||||
if (part === null) return 'null';
|
||||
|
||||
const props = [
|
||||
`name: "${part.component.name}"`,
|
||||
`component: ${part.component.name}`
|
||||
|
||||
@@ -101,27 +101,21 @@ export default function create_routes(cwd = locations.routes()) {
|
||||
|
||||
if (item.is_dir) {
|
||||
const index = path.join(dir, item.basename, '_layout.html');
|
||||
const layout = fs.existsSync(index)
|
||||
? {
|
||||
name: `${get_slug(item.file)}__layout`,
|
||||
file: `${item.file}/_layout.html`
|
||||
}
|
||||
: null;
|
||||
|
||||
if (layout) {
|
||||
components.push(layout);
|
||||
} else if (components.indexOf(default_layout) === -1) {
|
||||
components.push(default_layout);
|
||||
}
|
||||
const component = fs.existsSync(index) && {
|
||||
name: `${get_slug(item.file)}__layout`,
|
||||
file: `${item.file}/_layout.html`
|
||||
};
|
||||
|
||||
if (component) components.push(component);
|
||||
|
||||
walk(
|
||||
path.join(dir, item.basename),
|
||||
segments,
|
||||
params,
|
||||
stack.concat({
|
||||
component: layout || default_layout,
|
||||
params
|
||||
})
|
||||
component
|
||||
? stack.concat({ component, params })
|
||||
: stack.concat(null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user