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

Commit 181c94d

Browse files
authored
docs: adds multiple params examples (#1077)
1 parent d99d67b commit 181c94d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

site/content/docs/02-routing.md

+16
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ Dynamic parameters are encoded using `[brackets]`. For example, here's how you c
7070
</div>
7171
```
7272

73+
If you want to capture more params, you can create nested folders using the same naming convention: `[slug]/[language]`.
74+
75+
If you don't want to create several folders to capture more than one parameter like `[year]/[month]/...`, or if the number of parameters is dynamic, you can use a spread route parameter. For example, instead of individually capturing `/blog/[slug]/[year]/[month]/[day]`, you can create a file for `/blog/[...slug].svelte` and extract the params like so:
76+
77+
```html
78+
<!-- src/routes/blog/[...slug].svelte -->
79+
<script context="module">
80+
export async function preload({ params }) {
81+
let [slug, year, month, day] = params.slug;
82+
83+
return { slug, year, month, day };
84+
}
85+
</script>
86+
```
87+
88+
7389
> See the section on [preloading](docs#Preloading) for more info about `preload` and `this.fetch`
7490
7591

0 commit comments

Comments
 (0)