0
0
Svelteframework~20 mins

File-based routing in Svelte - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
šŸŽ–ļø
File-based Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ā“ component_behavior
intermediate
2:00remaining
What component renders for the URL /blog/42?
Given this file structure in a SvelteKit project:

src/routes/
ā”œā”€ā”€ +page.svelte
ā”œā”€ā”€ blog/
│   ā”œā”€ā”€ +page.svelte
│   └── [id]/+page.svelte
└── about/+page.svelte

Which component will render when the user visits /blog/42?
Asrc/routes/blog/+page.svelte
Bsrc/routes/blog/[id]/+page.svelte
Csrc/routes/+page.svelte
Dsrc/routes/about/+page.svelte
Attempts:
2 left
šŸ’” Hint
Dynamic segments in file names match URL parts like numbers or words.
šŸ“ Syntax
intermediate
2:00remaining
Which file name correctly defines a catch-all route?
In SvelteKit file-based routing, which file name correctly matches all routes under /docs, including nested paths like /docs/intro/setup?
Asrc/routes/docs/[all]/+page.svelte
Bsrc/routes/docs/[all...]/+page.svelte
Csrc/routes/docs/[...all]/+layout.svelte
Dsrc/routes/docs/[...all]/+page.svelte
Attempts:
2 left
šŸ’” Hint
Catch-all routes use three dots inside square brackets.
šŸ”§ Debug
advanced
2:00remaining
Why does /profile show a 404 error?
Given this file structure:

src/routes/
ā”œā”€ā”€ +page.svelte
ā”œā”€ā”€ profile/[user]/+page.svelte

Visiting /profile shows a 404 error. Why?
ABecause <code>profile/+page.svelte</code> is a directory, not a file.
BBecause <code>profile/+page.svelte</code> is missing an <code>+layout.svelte</code> file.
CBecause <code>profile/+page.svelte</code> is missing.
DBecause the <code>profile</code> folder is missing a <code>+page.server.js</code> file.
Attempts:
2 left
šŸ’” Hint
The route folder must contain a +page.svelte file directly for the path to work.
ā“ state_output
advanced
2:00remaining
What is the value of params.id for URL /shop/123?
Given this file: src/routes/shop/[id]/+page.svelte with this script:

<script>
  export let params;
</script>

<p>ID: {params.id}</p>

What will be displayed when visiting /shop/123?
AID: 123
BID: shop
CID: undefined
DID: [id]
Attempts:
2 left
šŸ’” Hint
Dynamic segments in the file name become keys in the params object.
🧠 Conceptual
expert
3:00remaining
Which file handles the route /dashboard/settings/profile?
Given this file structure:

src/routes/
ā”œā”€ā”€ dashboard/+layout.svelte
ā”œā”€ā”€ dashboard/settings/+page.svelte
ā”œā”€ā”€ dashboard/settings/profile/+page.svelte
ā”œā”€ā”€ dashboard/settings/profile/+layout.svelte

Which file is responsible for rendering the content at /dashboard/settings/profile?
Asrc/routes/dashboard/settings/profile/+page.svelte
Bsrc/routes/dashboard/settings/+page.svelte
Csrc/routes/dashboard/+layout.svelte
Dsrc/routes/dashboard/settings/profile/+layout.svelte
Attempts:
2 left
šŸ’” Hint
Layouts wrap pages but do not replace them.