mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 21:04:34 +00:00
Merge pull request #539 from cudr/nested-routes-navigate-fix
Fix nested routes navigates
This commit is contained in:
@@ -36,7 +36,7 @@ const root_props: RootProps = {
|
|||||||
|
|
||||||
export let prefetching: {
|
export let prefetching: {
|
||||||
href: string;
|
href: string;
|
||||||
promise: Promise<{ redirect?: Redirect, data?: any, nullable_depth?: number }>;
|
promise: Promise<{ redirect?: Redirect, data?: any, nullable_depth?: number, new_segments?: any }>;
|
||||||
} = null;
|
} = null;
|
||||||
export function set_prefetching(href, promise) {
|
export function set_prefetching(href, promise) {
|
||||||
prefetching = { href, promise };
|
prefetching = { href, promise };
|
||||||
@@ -137,10 +137,13 @@ export function navigate(target: Target, id: number, noscroll?: boolean, hash?:
|
|||||||
|
|
||||||
const token = current_token = {};
|
const token = current_token = {};
|
||||||
|
|
||||||
return loaded.then(({ redirect, data, nullable_depth }) => {
|
return loaded.then(({ redirect, data, nullable_depth, new_segments }) => {
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
return goto(redirect.location, { replaceState: true });
|
return goto(redirect.location, { replaceState: true });
|
||||||
}
|
}
|
||||||
|
if (new_segments) {
|
||||||
|
segments = new_segments;
|
||||||
|
}
|
||||||
render(data, nullable_depth, scroll_history[id], noscroll, hash, token);
|
render(data, nullable_depth, scroll_history[id], noscroll, hash, token);
|
||||||
if (document.activeElement) document.activeElement.blur();
|
if (document.activeElement) document.activeElement.blur();
|
||||||
});
|
});
|
||||||
@@ -285,11 +288,9 @@ export function prepare_page(target: Target): Promise<{
|
|||||||
}
|
}
|
||||||
}).then(results => {
|
}).then(results => {
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
return { redirect };
|
return { redirect, new_segments };
|
||||||
}
|
}
|
||||||
|
|
||||||
segments = new_segments;
|
|
||||||
|
|
||||||
const get_params = page.parts[page.parts.length - 1].params || (() => ({}));
|
const get_params = page.parts[page.parts.length - 1].params || (() => ({}));
|
||||||
const params = get_params(target.match);
|
const params = get_params(target.match);
|
||||||
|
|
||||||
@@ -303,6 +304,7 @@ export function prepare_page(target: Target): Promise<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
new_segments,
|
||||||
data: Object.assign({}, props, {
|
data: Object.assign({}, props, {
|
||||||
preloading: false,
|
preloading: false,
|
||||||
child: {
|
child: {
|
||||||
@@ -318,7 +320,7 @@ export function prepare_page(target: Target): Promise<{
|
|||||||
path,
|
path,
|
||||||
preloading: false,
|
preloading: false,
|
||||||
child: Object.assign({}, root_props.child, {
|
child: Object.assign({}, root_props.child, {
|
||||||
segment: segments[0]
|
segment: new_segments[0]
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
if (changed(query, root_props.query)) data.query = query;
|
if (changed(query, root_props.query)) data.query = query;
|
||||||
@@ -349,10 +351,10 @@ export function prepare_page(target: Target): Promise<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
level = level.props.child;
|
level = level.props.child;
|
||||||
level.segment = segments[i + 1];
|
level.segment = new_segments[i + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return { data, nullable_depth };
|
return { data, nullable_depth, new_segments };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,5 @@
|
|||||||
|
|
||||||
<a href="slow-preload">slow preload</a>
|
<a href="slow-preload">slow preload</a>
|
||||||
<a href="foo">foo</a>
|
<a href="foo">foo</a>
|
||||||
|
<a href="prefetch/qwe" rel=prefetch>prefetch qwe</a>
|
||||||
|
<a href="prefetch/xyz" rel=prefetch>prefetch xyz</a>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<h1>{params.slug}</h1>
|
||||||
1
test/apps/preloading/src/routes/prefetch/_layout.html
Normal file
1
test/apps/preloading/src/routes/prefetch/_layout.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svelte:component this={child.component} {...child.props}/>
|
||||||
1
test/apps/preloading/src/routes/prefetch/index.html
Normal file
1
test/apps/preloading/src/routes/prefetch/index.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<h1>prefetch</h1>
|
||||||
@@ -83,4 +83,31 @@ describe('preloading', function() {
|
|||||||
assert.equal(page.url(), `${base}/foo`);
|
assert.equal(page.url(), `${base}/foo`);
|
||||||
assert.equal(await title(), 'foo');
|
assert.equal(await title(), 'foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('navigates to prefetched urls', async () => {
|
||||||
|
await page.goto(base);
|
||||||
|
await start();
|
||||||
|
await prefetchRoutes();
|
||||||
|
|
||||||
|
await page.hover('a[href="prefetch/qwe"]');
|
||||||
|
await wait(100);
|
||||||
|
await page.hover('a[href="prefetch/xyz"]');
|
||||||
|
await wait(100);
|
||||||
|
|
||||||
|
await page.click('a[href="prefetch/qwe"]');
|
||||||
|
await wait(50);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await title(),
|
||||||
|
'qwe'
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.goto(`${base}/prefetch`);
|
||||||
|
await wait(50);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await title(),
|
||||||
|
'prefetch'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user