Rest parameters
Just as JavaScript functions can accept rest parameters using the rest operator (…
), so too can our routes. By using a rest operator inside of single square brackets, we can allow a variable length on the specified route. This feature comes in handy when creating something like a file browser where the URL should match a path that then makes the page content shareable via the URL.
To see this concept in action, let’s create a products
route in our store. Start by adding src/routes/store/products/+layout.svelte
so that we may navigate products easily:
src/routes/store/products/+layout.svelte
<h3>Products</h3> <ul> <li><a href="/store/products/shirts">Shirts</a></li> <li><a href="/store/products/shirts/mens">Mens Shirts</a></li> <li><a href="/store/products/shirts/mens/tshirts">Men's T-shirts ...