File-based routing makes it easy to create and manage pages by using your file names as web addresses. This means you don't have to write extra code to connect pages.
When building a website with many pages that need simple navigation.
When you want to quickly add new pages without changing routing code.
When you prefer organizing your project by folders and files that match URLs.
When you want to avoid mistakes from manually writing route paths.
When you want your project structure to clearly show the website's navigation.
4. You want to create a route /contact but your file is named src/pages/contact.astrox. What is the problem?
medium
A. The file extension is incorrect, so Astro won't recognize the route.
B. The file name should be contact/index.astro instead.
C. Astro requires a folder named contact with any file inside.
D. The route will work but only in development mode.
Solution
Step 1: Check file extension requirement
Astro requires page files to have .astro extension to create routes.
Step 2: Identify impact of wrong extension
contact.astrox is not recognized, so no route /contact is created.
Final Answer:
The file extension is incorrect, so Astro won't recognize the route. -> Option A
Quick Check:
Correct file extension = route created [OK]
Hint: Check file extensions carefully for routing [OK]
Common Mistakes:
Assuming any file extension works
Thinking folder structure fixes wrong extensions
Believing routes work without proper file names
5. You want to add a dynamic user profile route like /user/123 using file-based routing. Which file path correctly creates this dynamic route in Astro?
hard
A. src/pages/user/:id.astro
B. src/pages/user/id.astro
C. src/pages/user/_id.astro
D. src/pages/user/[id].astro
Solution
Step 1: Understand Astro dynamic route syntax
Astro uses square brackets [param] in file names to define dynamic route segments.
Step 2: Identify correct dynamic route file
src/pages/user/[id].astro creates a route matching /user/anything where id is dynamic.
Final Answer:
src/pages/user/[id].astro -> Option D
Quick Check:
Dynamic routes use [param] syntax [OK]
Hint: Use [param] in file name for dynamic routes [OK]
Common Mistakes:
Using colons or underscores instead of brackets
Naming files literally as 'id.astro' for dynamic routes
Confusing dynamic route syntax with other frameworks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.