Routing for Sveltes
Routing in SvelteKit maps the folder structure under src/routes to URLs, so a +page.svelte file in a directory becomes a page. Dynamic segments in square brackets capture parameters, and load functions in +page.js or +page.server.js fetch the data a page needs before it renders.
Stage: SvelteKit · Part of the Svelte roadmap · Last reviewed 19 November 2026
What to learn in Routing
- Create pages and nested layouts with +page.svelte and +layout.svelte
- Capture URL parameters using bracketed folder names like [slug]
- Write a load function that returns data to the page
- Decide between universal load and server-only load
- Navigate with anchor links and the goto function
- Handle missing data by throwing a 404 error
Routing interview questions
What is the difference between +page.js and +page.server.js in SvelteKit?
A load function in +page.js is universal: it runs on the server for the first request and in the browser afterwards. One in +page.server.js runs only on the server, so it can read secrets, use a database and return only serialisable data.
How does a layout share data with its child pages?
A +layout.js or +layout.server.js load function returns data that is merged into the data every nested page receives. Child pages can read it from the data prop or the parent function, avoiding repeated fetching.
Where Routing fits in the Svelte roadmap
Routing belongs to the SvelteKit stage (intermediate level). Full-stack.
Other units in this stage
Back to the full Svelte roadmap