0
0
Vueframework~20 mins

Defining routes in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Router Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Vue Router configuration render?

Given the following Vue Router setup, what component will display when the URL path is /about?

Vue
import { createRouter, createWebHistory } from 'vue-router';
import Home from './components/Home.vue';
import About from './components/About.vue';

const routes = [
  { path: '/', component: Home },
  { path: '/about', component: About }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

export default router;
ANo component will render; the page will be blank.
BThe Home component will render.
CThe About component will render.
DBoth Home and About components will render simultaneously.
Attempts:
2 left
💡 Hint

Check which component is linked to the /about path in the routes array.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a nested route in Vue Router?

Choose the correct syntax to define a nested route where /dashboard/settings loads the Settings component inside Dashboard.

Aconst routes = [{ path: '/dashboard', component: Dashboard, nested: [{ path: 'settings', component: Settings }] }];
Bconst routes = [{ path: '/dashboard/settings', component: Settings, parent: Dashboard }];
Cconst routes = [{ path: '/dashboard', component: Dashboard }, { path: '/dashboard/settings', component: Settings }];
Dconst routes = [{ path: '/dashboard', component: Dashboard, children: [{ path: 'settings', component: Settings }] }];
Attempts:
2 left
💡 Hint

Nested routes use the children property with relative paths.

🔧 Debug
advanced
2:00remaining
Why does this route configuration cause a navigation error?

Consider this Vue Router setup. Why will navigating to /profile/edit cause an error?

Vue
const routes = [
  { path: '/profile/edit', component: () => import('./EditProfile.vue') },
  { path: '/profile/:id', component: () => import('./Profile.vue') }
];
ABecause the more specific route <code>/profile/edit</code> is defined after <code>/profile/:id</code>, causing a matching conflict.
BBecause dynamic imports cannot be used in route components.
CBecause the paths are missing a trailing slash.
DBecause the routes array must have a unique name property for each route.
Attempts:
2 left
💡 Hint

Think about how Vue Router matches routes in order and the importance of route specificity.

state_output
advanced
2:00remaining
What is the value of $route.params.id after navigating to /user/42?

Given this route definition, what will $route.params.id contain after navigating to /user/42?

Vue
const routes = [
  { path: '/user/:id', component: UserProfile }
];
A"id"
B"42"
Cundefined
D42 (number)
Attempts:
2 left
💡 Hint

Route parameters are always strings in Vue Router.

🧠 Conceptual
expert
2:00remaining
Which option best describes the purpose of in Vue Router?

What does the <router-view> component do in a Vue app using Vue Router?

A<router-view> is a placeholder where matched route components are rendered dynamically.
B<router-view> defines the navigation links for the app's routes.
C<router-view> is used to declare routes in the Vue Router configuration.
D<router-view> automatically fetches data for the current route.
Attempts:
2 left
💡 Hint

Think about where the content of the current route appears in the app.