Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Navigate from /a/[id] to /b/[id] fix #610

Merged
merged 3 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export async function hydrate_target(target: Target): Promise<{
const j = l++;

const segment = segments[i];
if (!session_dirty && current_branch[i] && current_branch[i].segment === segment) return current_branch[i];
if (!session_dirty && current_branch[i] && current_branch[i].segment === segment && current_branch[i].part === part.i) return current_branch[i];

const { default: component, preload } = await load_component(components[part.i]);

Expand All @@ -306,7 +306,7 @@ export async function hydrate_target(target: Target): Promise<{
preloaded = initial_data.preloaded[i + 1];
}

return (props[`level${j}`] = { component, props: preloaded, segment });
return (props[`level${j}`] = { component, props: preloaded, segment, part: part.i });
}));
} catch (error) {
props.error = error;
Expand Down
3 changes: 3 additions & 0 deletions test/apps/basics/src/routes/dirs/bar/[a].svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>A page</h1>

<a href="dirs/foo/xyz">same segment</a>
1 change: 1 addition & 0 deletions test/apps/basics/src/routes/dirs/foo/[b].svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>B page</h1>
11 changes: 11 additions & 0 deletions test/apps/basics/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ describe('basics', function() {
assert.equal(await title(), 'bar');
});

it('navigates between dynamic routes with same segments', async () => {
await page.goto(`${base}/dirs/bar/xyz`);
await start();

assert.equal(await title(), 'A page');

await page.click('[href="dirs/foo/xyz"]');
await wait(50);
assert.equal(await title(), 'B page');
});

it('runs server route handlers before page handlers, if they match', async () => {
const json = await get(`${base}/middleware`, {
headers: {
Expand Down