Slot-based routing (#573)

This commit is contained in:
Rich Harris
2019-02-21 16:34:07 -05:00
committed by GitHub
parent c637687922
commit e0de230e13
22 changed files with 141 additions and 99 deletions

View File

@@ -1 +0,0 @@
<h1>{params.slug.toUpperCase()}</h1>

View File

@@ -12,10 +12,10 @@
import { page } from '@sapper/app';
export let count;
export let child;
export let segment;
</script>
<span>y: {$page.params.y} {count}</span>
<svelte:component this={child.component} {...child.props}/>
<slot></slot>
<span>child segment: {child.segment}</span>
<span>child segment: {segment}</span>

View File

@@ -28,7 +28,7 @@ describe('layout', function() {
await page.goto(`${base}/foo/bar/baz`);
const text1 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text1.split('\n').filter(Boolean).map(str => str.trim()), [
assert.deepEqual(text1.split('\n').map(str => str.trim()).filter(Boolean), [
'y: bar 1',
'z: baz 1',
'click me',
@@ -37,7 +37,7 @@ describe('layout', function() {
await start();
const text2 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text2.split('\n').filter(Boolean).map(str => str.trim()), [
assert.deepEqual(text2.split('\n').map(str => str.trim()).filter(Boolean), [
'y: bar 1',
'z: baz 1',
'click me',
@@ -48,7 +48,7 @@ describe('layout', function() {
await wait(50);
const text3 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text3.split('\n').filter(Boolean).map(str => str.trim()), [
assert.deepEqual(text3.split('\n').map(str => str.trim()).filter(Boolean), [
'y: bar 1',
'z: qux 2',
'click me',

View File

@@ -8,13 +8,16 @@
<script>
import { preloading } from '@sapper/app';
import { setContext } from 'svelte';
export let child;
export let rootPreloadFunctionRan;
setContext('x', { rootPreloadFunctionRan });
</script>
{#if $preloading}
<progress class='preloading-progress' value=0.5/>
{/if}
<svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/>
<slot></slot>

View File

@@ -1 +0,0 @@
<svelte:component this={child.component} {...child.props}/>

View File

@@ -1 +0,0 @@
<h1>root preload function ran: {rootPreloadFunctionRan}</h1>

View File

@@ -0,0 +1,6 @@
<script>
import { getContext } from 'svelte';
const { rootPreloadFunctionRan } = getContext('x');
</script>
<h1>root preload function ran: {rootPreloadFunctionRan}</h1>

View File

@@ -1 +0,0 @@
<svelte:component this={child.component} {...child.props}/>