Challenge - 5 Problems
File-based Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What does this Vue page component render?
Given a file named
src/pages/About.vue in a Vue 3 app using file-based routing, what will the page display when navigating to /about?Vue
<template>
<section>
<h1>About Us</h1>
<p>Welcome to our site!</p>
</section>
</template>
<script setup>
// no script needed
</script>Attempts:
2 left
💡 Hint
Think about how Vue file-based routing maps file names to URLs and renders the template.
✗ Incorrect
In Vue file-based routing, the file
About.vue inside pages folder maps to the /about URL. The template content is rendered as the page content.📝 Syntax
intermediate1:00remaining
Which file name creates a dynamic route for user profiles?
In Vue file-based routing, which file name inside
src/pages correctly creates a dynamic route to match URLs like /user/123 where 123 is a user ID?Attempts:
2 left
💡 Hint
Vue uses square brackets for dynamic route parameters in file names.
✗ Incorrect
In Vue file-based routing, dynamic route parameters are defined by enclosing the parameter name in square brackets, like
[id].vue.🔧 Debug
advanced2:00remaining
Why does this nested route not render the child page?
Given these files:
-
src/pages/dashboard.vue
- src/pages/dashboard/settings.vue
Navigating to /dashboard/settings shows a blank page. Why?Attempts:
2 left
💡 Hint
Think about how nested routes display their children in Vue.
✗ Incorrect
Nested routes require the parent component to include a
<router-view> element where child routes render. Without it, child pages won't appear.❓ state_output
advanced1:30remaining
What is the value of the route param in this page?
In a Vue page component
src/pages/blog/[slug].vue, the script setup contains:
import { useRoute } from 'vue-router';
const route = useRoute();
const slug = route.params.slug;
If the user visits /blog/vue-routing, what is the value of slug?Attempts:
2 left
💡 Hint
Route params capture the dynamic part of the URL matching the file name.
✗ Incorrect
The dynamic segment
[slug] captures the part of the URL after /blog/. So visiting /blog/vue-routing sets slug to "vue-routing".🧠 Conceptual
expert2:30remaining
Which option correctly describes the behavior of catch-all routes in Vue file-based routing?
You want to create a catch-all route that matches any path not matched by other routes, for example to show a 404 page. Which file name inside
src/pages achieves this?Attempts:
2 left
💡 Hint
Catch-all routes use a special syntax with three dots inside square brackets.
✗ Incorrect
In Vue file-based routing, catch-all routes are defined by files named with three dots inside square brackets, like
[...all].vue. This matches any unmatched path.