mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 05:25:08 +00:00
fix fallback index file
This commit is contained in:
@@ -4,7 +4,7 @@ import { locations } from '../config';
|
|||||||
import { Page, PageComponent, ServerRoute } from '../interfaces';
|
import { Page, PageComponent, ServerRoute } from '../interfaces';
|
||||||
import { posixify } from './utils';
|
import { posixify } from './utils';
|
||||||
|
|
||||||
const fallback_index = posixify(path.resolve(
|
const fallback_file = posixify(path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../fallback.html'
|
'../fallback.html'
|
||||||
));
|
));
|
||||||
@@ -14,6 +14,11 @@ export default function create_routes(cwd = locations.routes()) {
|
|||||||
const pages: Page[] = [];
|
const pages: Page[] = [];
|
||||||
const server_routes: ServerRoute[] = [];
|
const server_routes: ServerRoute[] = [];
|
||||||
|
|
||||||
|
const fallback = {
|
||||||
|
name: 'fallback',
|
||||||
|
file: path.relative(cwd, fallback_file)
|
||||||
|
};
|
||||||
|
|
||||||
function walk(
|
function walk(
|
||||||
dir: string,
|
dir: string,
|
||||||
parent_segments: Part[][],
|
parent_segments: Part[][],
|
||||||
@@ -104,17 +109,18 @@ export default function create_routes(cwd = locations.routes()) {
|
|||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (component) components.push(component);
|
if (component) {
|
||||||
|
components.push(component);
|
||||||
|
} else if (components.indexOf(fallback) === -1) {
|
||||||
|
components.push(fallback);
|
||||||
|
}
|
||||||
|
|
||||||
walk(
|
walk(
|
||||||
path.join(dir, item.basename),
|
path.join(dir, item.basename),
|
||||||
segments,
|
segments,
|
||||||
params,
|
params,
|
||||||
stack.concat({
|
stack.concat({
|
||||||
component: component || {
|
component: component || fallback,
|
||||||
name: 'fallback',
|
|
||||||
file: fallback_index
|
|
||||||
},
|
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
1
test/app/routes/missing-index/ok.html
Normal file
1
test/app/routes/missing-index/ok.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<h1>it works</h1>
|
||||||
@@ -659,6 +659,14 @@ function run({ mode, basepath = '' }) {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses a fallback index component if none is provided', () => {
|
||||||
|
return nightmare.goto(`${base}/missing-index/ok`)
|
||||||
|
.page.title()
|
||||||
|
.then(title => {
|
||||||
|
assert.equal(title, 'it works');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user