A dynamic route parameter is a part of the URL path that can change and is captured as a variable in the route. It allows pages to handle different data based on the URL, like showing a user profile by ID.
Click to reveal answer
beginner
How do you define a dynamic route parameter in a SvelteKit file path?
You define it by wrapping the parameter name in square brackets in the file name. For example, src/routes/user/[id].svelte captures the id from the URL.
Click to reveal answer
intermediate
How do you access a dynamic route parameter inside a SvelteKit page component?
You use the page store from $app/stores or the params object in load functions to get the parameter value, like params.id.
Click to reveal answer
beginner
What happens if you visit a URL that does not match any dynamic route parameter pattern?
SvelteKit will show a 404 page because no route matches the URL pattern. Dynamic routes only match URLs that fit their parameter structure.
Click to reveal answer
intermediate
Can you have multiple dynamic parameters in one route? How?
Yes, you can have multiple parameters by adding multiple bracketed names in the file path, like src/routes/blog/[category]/[post].svelte. Each parameter is accessible separately.
Click to reveal answer
How do you name a file to capture a dynamic parameter called 'userId' in SvelteKit?
A{userId}.svelte
B[userId].svelte
CuserId.svelte
D(userId).svelte
✗ Incorrect
Dynamic parameters are wrapped in square brackets in the file name, like [userId].svelte.
Where can you access the dynamic route parameters inside a SvelteKit page?
AIn the <code>params</code> object of the <code>load</code> function
BIn the <code>props</code> of the component
CIn the <code>window.location</code> object
DIn the <code>document</code> object
✗ Incorrect
Dynamic parameters are accessed via the params object passed to the load function.
What URL would match the route file src/routes/product/[id].svelte?
A/product
B/product?id=123
C/product/123
D/product/123/details
✗ Incorrect
The URL /product/123 matches the dynamic parameter id in the route.
Can a dynamic route parameter contain slashes '/' in its value?
AYes, but only numbers
BYes, it matches the whole rest of the URL
COnly if you use special syntax
DNo, it matches only one segment between slashes
✗ Incorrect
Dynamic parameters match exactly one segment between slashes, not multiple segments.
How do you define a route with two dynamic parameters 'category' and 'post'?
Asrc/routes/[category]/[post].svelte
Bsrc/routes/category/post.svelte
Csrc/routes/[category-post].svelte
Dsrc/routes/(category)/(post).svelte
✗ Incorrect
Each dynamic parameter is wrapped in its own square brackets in the folder structure.
Explain how dynamic route parameters work in SvelteKit and how you use them in your code.
Think about how URLs change and how your app knows which data to show.
You got /4 concepts.
Describe how you would create a blog post page that uses dynamic route parameters for category and post ID.
Imagine URLs like /blog/tech/123 and how your files match that.
You got /4 concepts.
Practice
(1/5)
1. What does a filename like [id].svelte represent in a SvelteKit project?
easy
A. A dynamic route where id is a variable part of the URL
B. A static page named literally 'id'
C. A component that cannot be accessed via URL
D. A special file for global styles
Solution
Step 1: Understand filename brackets in SvelteKit
Square brackets in filenames define dynamic segments in routes, meaning the part inside brackets is a variable.
Step 2: Interpret [id].svelte
This means the page matches URLs like /123 or /abc, where id changes dynamically.
Final Answer:
A dynamic route where id is a variable part of the URL -> Option A
Quick Check:
Filename with brackets = dynamic route [OK]
Hint: Brackets in filename mean dynamic URL part [OK]
Common Mistakes:
Thinking bracket means static filename
Confusing dynamic route with component name
Assuming it is for styles or scripts
2. Which is the correct way to access a dynamic route parameter named slug inside a SvelteKit page component?
easy
A. Using export let params; in the script
B. Using window.slug in the script
C. Using const { slug } = params; inside load function
D. Using this.slug in the component
Solution
Step 1: Recall how SvelteKit passes route params
Dynamic route parameters are passed to the page component as a params prop object.
Step 2: Declare the prop in the script
Inside the page component (+page.svelte) script, use export let params; to receive it, then access params.slug.
Final Answer:
Using export let params; in the script -> Option A
Quick Check:
export let params; receives route params [OK]
Hint: export let params; in page script [OK]
Common Mistakes:
Using export let slug; (wrong prop name)
Accessing params from window or this
Confusing with load function params
3. Given a file named src/routes/blog/[postId].svelte with this code:
<script>
export let params;
</script>
<h1>Post ID: {params.postId}</h1>
The [postId].svelte file captures the URL segment after /blog/ as postId and passes it as params.postId.
Step 2: Check how params is used in the component
The component uses {params.postId} inside the heading, so it will display the actual value from the URL.
Final Answer:
<h1>Post ID: 42</h1> -> Option B
Quick Check:
Dynamic param value shown = 42 [OK]
Hint: Dynamic param in URL shows inside {params.paramName} [OK]
Common Mistakes:
Expecting literal string 'postId' instead of value
Forgetting to export params
Using params without export or load
4. You have a dynamic route file [user].svelte but when you visit /john, you get an error: params is undefined. What is the likely cause?
medium
A. You must use window.params to access parameters
B. You named the file incorrectly; it should be {user}.svelte
C. You forgot to export let params in the script
D. Dynamic routes do not support parameters
Solution
Step 1: Check how params are accessed in SvelteKit
Dynamic route parameters are passed as a prop named params which must be exported in the script.
Step 2: Identify missing export
If let params is not exported, the component cannot access it, causing params is undefined.
Final Answer:
You forgot to export let params in the script -> Option C
Quick Check:
Export params to access dynamic route data [OK]
Hint: Always export let params to use route parameters [OK]
Common Mistakes:
Using curly braces in filename instead of brackets
Trying to access params from window object
Assuming dynamic routes don't pass params
5. You want to create a nested dynamic route in SvelteKit to show a user's post detail at URL /user/123/post/456. Which file structure and parameter access is correct?
hard
A. Files: src/routes/user/[userId]/post.svelte Access: params.userId only
B. Files: src/routes/user/[userId]/post/[postId].svelte Access: params.user and params.post
C. Files: src/routes/user/post/[postId].svelte Access: params.userId and params.postId
D. Files: src/routes/user/[userId]/post/[postId].svelte Access: params.userId and params.postId
Solution
Step 1: Understand nested dynamic routes in SvelteKit
To match URL segments like /user/123/post/456, you create nested folders with dynamic filenames for each variable part.
Step 2: Confirm file structure and parameter names
The correct structure is user/[userId]/post/[postId].svelte, and inside the component, you access params.userId and params.postId.
Final Answer:
Files: src/routes/user/[userId]/post/[postId].svelte and access params.userId and params.postId -> Option D
Quick Check:
Nested dynamic folders match URL segments [OK]
Hint: Use nested folders with brackets for each dynamic segment [OK]
Common Mistakes:
Using wrong param names inside params object
Missing nested folder for second dynamic segment
Trying to access params not defined by filename
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.