0Pricing
Sveltejs Academy · Lesson

Optional and Rest Parameters

Handle optional segments with [[optional]] and catch-all routes with [...rest].

Optional Segments

Use double brackets [[optional]] to make a segment optional.

src/routes/[[lang]]/about/+page.svelte

Both URLs Match

The above matches both /about and /en/about. lang is undefined for the first.

All lessons in this course

  1. File-based Routing with +page.svelte
  2. Dynamic Route Parameters: [id]
  3. Optional and Rest Parameters
  4. Layout Files: +layout.svelte
← Back to Sveltejs Academy