Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codify parameter matching behaviour #1373

Merged
merged 2 commits into from
May 7, 2021
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
2 changes: 2 additions & 0 deletions documentation/docs/01-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions packages/kit/test/apps/basics/src/routes/routing/__tests__.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import { page } from '$app/stores';
</script>

<h1>{$page.params.a}</h1>
<h2>{$page.params.b}</h2>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="/routing/split-params/x-y-z">/routing/split-params/x-y-z</a>