0
0
Vueframework~20 mins

Nested routes and child views in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Routes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will be rendered by this nested route setup?

Given the Vue Router configuration below, what will the user see when navigating to /dashboard/settings?

Vue
const routes = [
  {
    path: '/dashboard',
    component: DashboardLayout,
    children: [
      { path: '', component: DashboardHome },
      { path: 'settings', component: DashboardSettings }
    ]
  }
];
AOnly the DashboardSettings component content is shown.
BOnly DashboardLayout content is shown, no child components render.
CDashboardLayout wraps DashboardSettings content, showing both layouts and settings content.
DDashboardHome content is shown instead of DashboardSettings.
Attempts:
2 left
💡 Hint

Think about how parent and child components render together in nested routes.

📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this nested route definition

Which option contains the correct syntax for defining nested routes in Vue Router?

Vue
const routes = [
  {
    path: '/profile',
    component: ProfileLayout,
    children: [
      { path: 'info', component: ProfileInfo },
      { path: 'settings', component: ProfileSettings }
    ]
  }
];
Achildren: { path: 'info', component: ProfileInfo }
Bchildren: [ { path: 'info', component: ProfileInfo } ]
Cchildren: [ { path: '/info', component: ProfileInfo } ]
Dchildren: [ { path: '', component: ProfileInfo } ]
Attempts:
2 left
💡 Hint

Remember child paths should be relative, not absolute.

state_output
advanced
2:30remaining
What is the rendered output when navigating to a nested route with multiple ?

Consider a parent route with two nested child routes rendered in separate <router-view> elements. What will be displayed when navigating to /app/dashboard/overview?

Vue
const routes = [
  {
    path: '/app',
    component: AppLayout,
    children: [
      {
        path: 'dashboard',
        components: {
          default: DashboardMain,
          sidebar: DashboardSidebar
        },
        children: [
          { path: 'overview', component: DashboardOverview }
        ]
      }
    ]
  }
];
AAppLayout renders DashboardMain and DashboardSidebar, and DashboardOverview replaces DashboardMain.
BDashboardSidebar is not rendered because it is not a child route.
COnly DashboardOverview is rendered, others are replaced.
DAppLayout renders DashboardMain and DashboardSidebar, and DashboardOverview renders inside DashboardMain's <router-view>.
Attempts:
2 left
💡 Hint

Think about named views and nested child routes inside components.

🔧 Debug
advanced
2:30remaining
Why does the child route component not render inside the parent?

Given this route setup, the child component ChildView does not appear when navigating to /parent/child. What is the most likely cause?

Vue
const routes = [
  {
    path: '/parent',
    component: ParentView,
    children: [
      { path: 'child', component: ChildView }
    ]
  }
];

// ParentView.vue template:
// <template><div>Parent Content</div></template>
AParentView component is missing a <router-view> to display child routes.
BChildView path should start with a slash '/child' to render correctly.
CThe routes array must be flat; nested children are not supported.
DChildView component must be imported inside ParentView component.
Attempts:
2 left
💡 Hint

Check how child routes render inside parent components.

🧠 Conceptual
expert
3:00remaining
How does Vue Router handle nested route matching order?

When multiple nested routes match a URL, how does Vue Router decide which components to render?

AVue Router renders all matched nested routes from parent to deepest child in order.
BVue Router renders only the deepest matched child route component, ignoring parents.
CVue Router renders only the first matched route at the top level, ignoring children.
DVue Router randomly picks one matched route component to render.
Attempts:
2 left
💡 Hint

Think about how nested routes build up the page layout.