Explain it simply
Routing with Vue Router, in plain language
Vue Router is Vue's official client-side routing solution. createRouter maps URL paths to components, and RouterView renders whichever component matches. RouterLink updates the browser history without triggering a full page reload.
Problem → Why → Solution
The problem — why this concept matters
Forgetting to call app.use(router)
A common mistake
Mixing up route params and path when calling router.push
Core concept — understand how it works
Build single-page application navigation with Vue Router, switching views without a full page reload.
- URL or action
- Vue Router
- component view
Build a route table
Core syntax or pattern
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from './views/HomeView.vue'
import CourseView from './views/CourseView.vue'
export const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', name: 'home', component: HomeView },
{ path: '/courses/:slug', name: 'course', component: CourseView, props: true }
]
})Build single-page application navigation with Vue Router, switching views without a full page reload.
Read the code step by step
- URL or action
import { createRouter, createWebHistory } from 'vue-r...Vue Router is Vue's official client-side routing solution. createRouter maps URL paths to components, and RouterView renders whichever component matches. RouterLink updates the browser history without triggering a full page reload.
- Vue Router
routes: [Build single-page application navigation with Vue Router, switching views without a full page reload.
- component view
})Apply Routing with Vue Router in a small example and test normal, edge, and failure cases.
- URL or action
- Vue Router
- component view
Success
Build a route table
Failure
Forgetting to call app.use(router)
Let's break it down simply
Vue Router is Vue's official client-side routing solution. createRouter maps URL paths to components, and RouterView renders whichever component matches. RouterLink updates the browser history without triggering a full page reload.
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from './views/HomeView.vue'
import CourseView from './views/CourseView.vue'
export const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', name: 'home', component: HomeView },
{ path: '/courses/:slug', name: 'course', component: CourseView, props: true }
]
})/ → HomeView
/courses/vue → CourseView (slug: vue)Try it yourself
Build three routes — Home, Courses, and Course Detail — and add navigation links.
Vue Router — Getting Started — Vue Router
Real-world usage
How to apply it in a real project
Apply Routing with Vue Router in a small example and test normal, edge, and failure cases.
Mini challenge
Build it yourself
Build three routes — Home, Courses, and Course Detail — and add navigation links.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from './views/HomeView.vue'
import CourseView from './views/CourseView.vue'
export const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', name: 'home', component: HomeView },
{ path: '/courses/:slug', name: 'course', component: CourseView, props: true }
]
})Expected: Build a route table
Show hint
Apply Routing with Vue Router in a small example and test normal, edge, and failure cases.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- URL or action → Vue Router → component view
- Build single-page application navigation with Vue Router, switching views without a full page reload.
- Forgetting to call app.use(router)
- Apply Routing with Vue Router in a small example and test normal, edge, and failure cases.
Vue Router — Getting Started — Vue Router