0
0
Svelteframework~5 mins

File-based routing in Svelte - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is file-based routing in Svelte?
File-based routing means the app creates routes automatically based on the file names and folder structure inside the src/routes folder.
Click to reveal answer
beginner
How does SvelteKit map a file named src/routes/about/+page.svelte to a URL?
The file about/+page.svelte becomes the page at URL /about automatically.
Click to reveal answer
intermediate
What does a file named [id]/+page.svelte inside src/routes represent?
It represents a dynamic route where id is a variable part of the URL, like /123 or /abc.
Click to reveal answer
beginner
How do nested folders inside src/routes affect routing?
Nested folders create nested URL paths. For example, src/routes/blog/post/+page.svelte maps to /blog/post.
Click to reveal answer
beginner
What special file name is used to create the homepage in SvelteKit?
The file src/routes/+page.svelte creates the homepage at /.
Click to reveal answer
In SvelteKit, what URL does src/routes/contact/+page.svelte map to?
A/contact.svelte
B/src/routes/contact
C/contact
D/contact/index
What does a file named [slug]/+page.svelte inside src/routes/blog represent?
AAn error page
BA static page at /blog/slug
CA nested folder named slug
DA dynamic route matching /blog/anything
How do you create a nested route for /shop/products in SvelteKit?
ACreate <code>src/routes/shop/products/+page.svelte</code>
BCreate <code>src/routes/shop-products.svelte</code>
CBoth A and D are correct
DCreate <code>src/routes/shop/products/index.svelte</code>
Which file creates the homepage route / in SvelteKit?
Asrc/routes/home.svelte
Bsrc/routes/+page.svelte
Csrc/routes/index.svelte
DBoth B and C
What happens if you add a file named about/+page.svelte inside src/routes?
AIt creates a route at /about
BIt creates a route at /about/+page
CIt causes an error
DIt is ignored
Explain how file names and folder structure inside src/routes define the URLs in SvelteKit.
Think about how a website's pages are organized like folders and files on your computer.
You got /4 concepts.
    Describe how you would create a dynamic blog post page that shows different posts based on the URL.
    Imagine the URL changes but the page layout stays the same.
    You got /4 concepts.