Bird
Raised Fist0
Vueframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of nested routes in Vue Router?
easy
A. To load multiple Vue apps on the same page
B. To display child views inside a parent view using <router-view />
C. To create routes without components
D. To disable navigation guards

Solution

  1. Step 1: Understand nested routes concept

    Nested routes allow smaller views (child views) to be shown inside bigger views (parent views).
  2. Step 2: Identify how child views are displayed

    Child views appear inside the parent component where <router-view /> is placed.
  3. Final Answer:

    To display child views inside a parent view using <router-view /> -> Option B
  4. Quick Check:

    Nested routes = child views inside parent with <router-view /> [OK]
Hint: Nested routes show child views inside parents with [OK]
Common Mistakes:
  • Thinking nested routes load separate apps
  • Believing nested routes don't need
  • Confusing nested routes with route guards
2. Which of the following is the correct way to define a child route inside a parent route in Vue Router?
easy
A. { path: '/parent', component: Parent, children: [{ path: 'child', component: Child }] }
B. { path: '/parent/child', component: Child }
C. { path: '/parent', component: Parent, child: [{ path: 'child', component: Child }] }
D. { path: '/parent', component: Parent, children: { path: 'child', component: Child } }

Solution

  1. Step 1: Recall Vue Router child route syntax

    Child routes go inside a children array property of the parent route object.
  2. Step 2: Check each option's structure

    { path: '/parent', component: Parent, children: [{ path: 'child', component: Child }] } correctly uses children: [{ path: 'child', component: Child }]. Options C and D use wrong keys or types. { path: '/parent/child', component: Child } defines a separate route, not nested.
  3. Final Answer:

    { path: '/parent', component: Parent, children: [{ path: 'child', component: Child }] } -> Option A
  4. Quick Check:

    Child routes = inside children array [OK]
Hint: Child routes go inside a children array in parent route [OK]
Common Mistakes:
  • Using 'child' instead of 'children' key
  • Defining child routes outside parent route
  • Using object instead of array for children
3. Given this route config and components, what will be rendered when navigating to /dashboard/settings?
const routes = [
  { path: '/dashboard', component: Dashboard, children: [
    { path: 'settings', component: Settings }
  ]}
];

// Dashboard.vue template:
// 

Dashboard

// Settings.vue template: //

Settings Page

medium
A. Nothing renders due to missing
B.

Settings Page

C.

Dashboard

Settings Page

D.

Dashboard

Solution

  1. Step 1: Understand nested route rendering

    When visiting '/dashboard/settings', Vue renders Dashboard component first, then inside its <router-view /> renders Settings component.
  2. Step 2: Combine rendered HTML from both components

    Dashboard shows <h1>Dashboard</h1> and Settings shows <h2>Settings Page</h2>. Both appear together.
  3. Final Answer:

    <h1>Dashboard</h1><h2>Settings Page</h2> -> Option C
  4. Quick Check:

    Nested route renders parent + child views [OK]
Hint: Nested routes render parent plus child inside [OK]
Common Mistakes:
  • Expecting only child component to render
  • Forgetting in parent
  • Confusing full path with child path
4. What is wrong with this route configuration if child views do not appear?
const routes = [
  { path: '/profile', component: Profile, children: [
    { path: 'edit', component: EditProfile }
  ]}
];

// Profile.vue template:
// 

Profile Page

medium
A. Profile.vue is missing to display child routes
B. Child route path should start with '/'
C. Children array should be outside the parent route object
D. EditProfile component must be imported inside Profile.vue

Solution

  1. Step 1: Check how child routes display

    Child routes render inside the parent's <router-view />. Without it, child views won't show.
  2. Step 2: Inspect Profile.vue template

    Profile.vue only has <h1>Profile Page</h1> and no <router-view />, so child routes can't render.
  3. Final Answer:

    Profile.vue is missing <router-view /> to display child routes -> Option A
  4. Quick Check:

    Missing <router-view /> = no child views [OK]
Hint: Parent needs to show child routes [OK]
Common Mistakes:
  • Adding '/' at start of child path incorrectly
  • Placing children outside parent route object
  • Assuming child component imports affect rendering
5. You want to create a nested route where /shop shows a Shop component and /shop/products shows a Products component inside Shop. Which setup correctly achieves this and ensures accessibility and responsiveness? A) Define routes with children array, use <router-view /> in Shop, and add ARIA roles and responsive CSS. B) Define separate routes for /shop and /shop/products without nesting, and use CSS media queries only. C) Use nested routes but omit <router-view /> in Shop and rely on v-if to show Products. D) Use nested routes with children but place <router-view /> outside Shop component.
hard
A. Use nested routes but place outside Shop component
B. Define separate routes without nesting and use only CSS media queries
C. Use nested routes but omit in Shop and use v-if for Products
D. Define routes with children array, use in Shop, add ARIA roles and responsive CSS

Solution

  1. Step 1: Setup nested routes properly

    Use a children array in the /shop route to define /shop/products as a child route.
  2. Step 2: Ensure Shop component includes <router-view />

    This allows Products component to render inside Shop when navigating to /shop/products.
  3. Step 3: Add accessibility and responsiveness

    Use ARIA roles for landmarks and semantic HTML, plus responsive CSS (like Flexbox or Grid) to adapt layout on different screens.
  4. Final Answer:

    Define routes with children array, use <router-view /> in Shop, add ARIA roles and responsive CSS -> Option D
  5. Quick Check:

    Nested routes + router-view + accessibility + responsive CSS = Define routes with children array, use in Shop, add ARIA roles and responsive CSS [OK]
Hint: Nested routes need router-view in parent plus ARIA and responsive CSS [OK]
Common Mistakes:
  • Omitting router-view in parent component
  • Not adding ARIA roles for accessibility
  • Ignoring responsive design in CSS
  • Placing router-view outside parent component
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard