Merge branch 'master' into spread_routes

This commit is contained in:
Rich Harris
2019-04-27 13:09:54 -04:00
committed by GitHub
8 changed files with 27 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ sudo: false
language: node_js
node_js:
- "stable"
- "11"
env:
global:

View File

@@ -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]);
@@ -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;

View File

@@ -145,7 +145,7 @@ export function get_page_handler(
path: req.path,
query: req.query,
params: {}
})
}, session)
: {};
match = error ? null : page.pattern.exec(req.path);

View File

@@ -212,6 +212,6 @@ async function _export({
}
function get_href(attrs: string) {
const match = /href\s*=\s*(?:"(.*?)"|'(.+?)'|([^\s>]+))/.exec(attrs);
return match[1] || match[2] || match[3];
const match = /href\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/.exec(attrs);
return match && (match[1] || match[2] || match[3]);
}

View File

@@ -0,0 +1,3 @@
<h1>A page</h1>
<a href="dirs/foo/xyz">same segment</a>

View File

@@ -0,0 +1 @@
<h1>B page</h1>

View File

@@ -298,6 +298,17 @@ describe('basics', function() {
await page.evaluate(() => document.body.textContent),
'xyz,abc,qwe'
);
});
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 () => {

View File

@@ -1,4 +1,9 @@
<h1>Great success!</h1>
<a href="blog">blog</a>
<a href="">empty anchor</a>
<a href="">empty anchor</a>
<a href=''>empty anchor #2</a>
<a href=>empty anchor #3</a>
<a href= >empty anchor #4</a>
<a href>empty anchor #5</a>
<a>empty anchor #6</a>