From e5226bc67cbdc0cf0df09718fc9b3d1c81dcf1fe Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 6 May 2021 21:01:09 -0400 Subject: [PATCH 1/2] test for split params ambiguous behaviour (#1268) --- .../test/apps/basics/src/routes/routing/__tests__.js | 10 ++++++++++ .../src/routes/routing/split-params/[a]-[b].svelte | 6 ++++++ .../src/routes/routing/split-params/index.svelte | 1 + 3 files changed, 17 insertions(+) create mode 100644 packages/kit/test/apps/basics/src/routes/routing/split-params/[a]-[b].svelte create mode 100644 packages/kit/test/apps/basics/src/routes/routing/split-params/index.svelte diff --git a/packages/kit/test/apps/basics/src/routes/routing/__tests__.js b/packages/kit/test/apps/basics/src/routes/routing/__tests__.js index be93baa38cde..f6dbf76f3ca4 100644 --- a/packages/kit/test/apps/basics/src/routes/routing/__tests__.js +++ b/packages/kit/test/apps/basics/src/routes/routing/__tests__.js @@ -190,4 +190,14 @@ export default function (test) { await clicknav('[href="/routing/fallthrough/potato"]'); assert.equal(await page.textContent('h1'), '404'); }); + + test( + 'last parameter in a segment wins in cases of ambiguity', + '/routing/split-params', + async ({ page, clicknav }) => { + await clicknav('[href="/routing/split-params/x-y-z"]'); + assert.equal(await page.textContent('h1'), 'x'); + assert.equal(await page.textContent('h2'), 'y-z'); + } + ); } diff --git a/packages/kit/test/apps/basics/src/routes/routing/split-params/[a]-[b].svelte b/packages/kit/test/apps/basics/src/routes/routing/split-params/[a]-[b].svelte new file mode 100644 index 000000000000..79d7e8609222 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/routing/split-params/[a]-[b].svelte @@ -0,0 +1,6 @@ + + +

{$page.params.a}

+

{$page.params.b}

diff --git a/packages/kit/test/apps/basics/src/routes/routing/split-params/index.svelte b/packages/kit/test/apps/basics/src/routes/routing/split-params/index.svelte new file mode 100644 index 000000000000..fd96b1a05f31 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/routing/split-params/index.svelte @@ -0,0 +1 @@ +/routing/split-params/x-y-z From 97dd1240945fa518e53365cf2674afa75593a917 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 6 May 2021 21:03:21 -0400 Subject: [PATCH 2/2] docs --- documentation/docs/01-routing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/docs/01-routing.md b/documentation/docs/01-routing.md index 89d06ece62fd..3728204dd177 100644 --- a/documentation/docs/01-routing.md +++ b/documentation/docs/01-routing.md @@ -41,6 +41,8 @@ A file called either `src/routes/about.svelte` or `src/routes/about/index.svelte Dynamic parameters are encoded using `[brackets]`. For example, a blog post might be defined by `src/routes/blog/[slug].svelte`. Soon, we'll see how to access that parameter in a [load function](#loading) or the [page store](#modules-$app-stores). +A file or directory can have multiple dynamic parts, like `[id]-[category].svelte`. (Paramters are 'non-greedy'; in an ambiguous case like `x-y-z`, `id` would be `x` and `category` would be `y-z`.) + ### Endpoints Endpoints are modules written in `.js` (or `.ts`) files that export functions corresponding to HTTP methods. For example, our hypothetical blog page, `/blog/cool-article`, might request data from `/blog/cool-article.json`, which could be represented by a `src/routes/blog/[slug].json.js` endpoint: