mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
inject fallback index.html where necessary
This commit is contained in:
1
fallback.html
Normal file
1
fallback.html
Normal file
@@ -0,0 +1 @@
|
||||
<svelte:component this={child.component} {...child.props}/>
|
||||
@@ -3,6 +3,11 @@ import * as path from 'path';
|
||||
import { locations } from '../config';
|
||||
import { Page, PageComponent, ServerRoute } from '../interfaces';
|
||||
|
||||
const fallback_index = path.resolve(
|
||||
__dirname,
|
||||
'../fallback.html'
|
||||
);
|
||||
|
||||
export default function create_routes(cwd = locations.routes()) {
|
||||
const components: PageComponent[] = [];
|
||||
const pages: Page[] = [];
|
||||
@@ -90,7 +95,7 @@ export default function create_routes(cwd = locations.routes()) {
|
||||
params.push(...item.parts.filter(p => p.dynamic).map(p => p.content));
|
||||
|
||||
if (item.is_dir) {
|
||||
const index = path.join(dir, 'index.html');
|
||||
const index = path.join(dir, item.basename, 'index.html');
|
||||
const component = fs.existsSync(index)
|
||||
? {
|
||||
name: `page_${get_slug(item.file)}`,
|
||||
@@ -105,7 +110,10 @@ export default function create_routes(cwd = locations.routes()) {
|
||||
segments,
|
||||
params,
|
||||
stack.concat({
|
||||
component,
|
||||
component: component || {
|
||||
name: 'fallback',
|
||||
file: fallback_index
|
||||
},
|
||||
params
|
||||
})
|
||||
);
|
||||
|
||||
@@ -358,8 +358,6 @@ function get_page_handler(routes: RouteObject, store_getter: (req: Req) => Store
|
||||
store: store && try_serialize(store.get())
|
||||
};
|
||||
|
||||
console.log(serialized.preloaded);
|
||||
|
||||
const data = Object.assign({}, props, { params: req.params }, {
|
||||
child: {}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ const path = require('path');
|
||||
const assert = require('assert');
|
||||
const { create_routes } = require('../../../dist/core.ts.js');
|
||||
|
||||
describe.only('create_routes', () => {
|
||||
describe('create_routes', () => {
|
||||
it('creates routes', () => {
|
||||
const { components, pages, server_routes } = create_routes(path.join(__dirname, 'samples/basic'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user