File-based routing means the app's pages and URLs are created automatically from the files and folders in the project. Each file corresponds to a route.
Click to reveal answer
beginner
How does file-based routing reduce manual work?
You don't need to write code to define routes. Just create or rename files and folders, and the framework handles the navigation paths for you.
Click to reveal answer
beginner
Why is file-based routing easier for beginners?
Beginners can focus on building pages without learning complex routing code. The folder structure visually matches the website's navigation.
Click to reveal answer
intermediate
What happens if you rename a file in a file-based routing system?
The URL path changes automatically to match the new file name, so navigation updates without extra coding.
Click to reveal answer
intermediate
How does file-based routing help keep projects organized?
The folder and file structure directly shows the website's page hierarchy, making it easier to find and manage pages.
Click to reveal answer
What does file-based routing automatically create from your project files?
AUser accounts
BDatabase tables
CNavigation paths (URLs)
DCSS styles
✗ Incorrect
File-based routing links files and folders to navigation paths or URLs automatically.
Which action changes the URL in a file-based routing system?
ARenaming a file
BChanging CSS colors
CAdding JavaScript functions
DUpdating database records
✗ Incorrect
Renaming a file changes the route URL automatically in file-based routing.
Why is file-based routing good for beginners?
AOnly works with databases
BRequires complex setup
CNeeds manual URL mapping
DNo need to write routing code
✗ Incorrect
Beginners avoid writing routing code because routes come from files.
How does file-based routing help keep projects organized?
AFolder structure matches website pages
BAutomatically writes CSS
CGenerates user login forms
DCreates database schemas
✗ Incorrect
The folder and file layout shows the page hierarchy clearly.
What must you do to add a new page in file-based routing?
AUpdate the database
BCreate a new file in the pages folder
CWrite a new route in code
DModify CSS styles
✗ Incorrect
Adding a new file automatically creates a new route.
Explain how file-based routing simplifies navigation in a web project.
Think about how files relate to website pages and URLs.
You got /4 concepts.
Describe the benefits of using file-based routing for beginners.
Focus on simplicity and learning ease.
You got /4 concepts.
Practice
(1/5)
1. What is the main benefit of file-based routing in Astro's src/pages folder?
easy
A. Routes are created automatically from file names, so no extra routing code is needed.
B. You must write manual route definitions for each page.
C. It requires complex configuration files to work properly.
D. It only works for static websites, not dynamic ones.
Solution
Step 1: Understand file-based routing concept
In Astro, files inside src/pages automatically become routes based on their file names.
Step 2: Compare with manual routing
This means you don't need to write extra code to define routes, simplifying navigation setup.
Final Answer:
Routes are created automatically from file names, so no extra routing code is needed. -> Option A
Quick Check:
File names = Routes automatically [OK]
Hint: File names in pages folder become routes automatically [OK]
Common Mistakes:
Thinking manual route code is always required
Believing configuration files are needed for routing
Assuming file-based routing only works for static sites
2. Which of the following file paths correctly creates a route for /about/team in Astro?
easy
A. src/pages/team/about.astro
B. src/pages/about/team/index.astro
C. src/pages/about_team.astro
D. src/pages/about-team.astro
Solution
Step 1: Understand folder structure for nested routes
To create /about/team, you need a folder about with a file inside it for team.
Step 2: Identify correct file path
src/pages/about/team/index.astro creates the route /about/team because index.astro inside team folder maps to that path.
Final Answer:
src/pages/about/team/index.astro -> Option B
Quick Check:
Nested folders + index file = nested route [OK]
Hint: Nested folders with index.astro create nested routes [OK]
Common Mistakes:
Using dashes instead of folders for nested routes
Placing files directly without folders for nested paths
Confusing underscores with dashes in file names
3. Given these files in src/pages: index.astro, blog/index.astro, blog/post.astro What routes will be available on the website?
medium
A. /, /blog, /post
B. /index, /blog/index, /blog/post
C. /, /blog, /blog/post
D. /index, /blog, /post
Solution
Step 1: Map files to routes
index.astro maps to /, blog/index.astro maps to /blog, and blog/post.astro maps to /blog/post.
Step 2: Check for correct route paths
Routes reflect folder structure and file names without index in URL.
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.