Skip to content

Commit d31eb66

Browse files
author
Rich Harris
authored
Codify parameter matching behaviour (#1373)
* test for split params ambiguous behaviour (#1268) * docs
1 parent 6979df0 commit d31eb66

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

documentation/docs/01-routing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ A file called either `src/routes/about.svelte` or `src/routes/about/index.svelte
4141

4242
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).
4343

44+
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`.)
45+
4446
### Endpoints
4547

4648
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:

packages/kit/test/apps/basics/src/routes/routing/__tests__.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,14 @@ export default function (test) {
190190
await clicknav('[href="/routing/fallthrough/potato"]');
191191
assert.equal(await page.textContent('h1'), '404');
192192
});
193+
194+
test(
195+
'last parameter in a segment wins in cases of ambiguity',
196+
'/routing/split-params',
197+
async ({ page, clicknav }) => {
198+
await clicknav('[href="/routing/split-params/x-y-z"]');
199+
assert.equal(await page.textContent('h1'), 'x');
200+
assert.equal(await page.textContent('h2'), 'y-z');
201+
}
202+
);
193203
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { page } from '$app/stores';
3+
</script>
4+
5+
<h1>{$page.params.a}</h1>
6+
<h2>{$page.params.b}</h2>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="/routing/split-params/x-y-z">/routing/split-params/x-y-z</a>

0 commit comments

Comments
 (0)