CHAPTER 14
Beginner
Vue Router Basics
Updated: May 18, 2026
5 min read
# CHAPTER 14
Vue Router Basics
1. Chapter Introduction
Vue Router is the official client-side routing library for Vue. It enables Single Page Application (SPA) navigation — clicking links changes the URL and renders different components WITHOUT page reloads. This is what makes Vue apps feel instant.2. Learning Objectives
- Set up Vue Router in a Vue 3 project.
- Define routes and map them to components.
-
Use
<RouterLink>and<RouterView>.
- Navigate programmatically.
- Build a multi-page application.
3. Installation and Setup
bash
javascript
javascript
4. RouterView and RouterLink
vue
5. Programmatic Navigation
vue
6. Mini Project: Multi-Page Application
javascript
vue
7. Common Mistakes
-
Using
<a href="/about">instead of<RouterLink to="/about">: Regular<a>tags cause full page reloads. Always use<RouterLink>for in-app navigation.
-
Not having a 404 catch-all route: Without
/:pathMatch(.*)*, invalid URLs render nothing. Always add a 404 route as the last route.
8. MCQs
Question 1
What component renders the matched route?
Question 2
<RouterLink to="/about"> renders as?
Question 3
Lazy loading a route component uses?
Question 4
useRouter() gives access to?
Question 5
useRoute() gives access to?
Question 6
router.replace('/login') vs router.push('/login')?
Question 7
createWebHistory requires?
Question 8
Named routes are accessed with?
Question 9
router-link-exact-active class is added when?
Question 10
Catch-all 404 route path?
9. Interview Questions
-
Q: What is the difference between
<RouterLink>and an HTML<a>tag?
- Q: How does Vue Router enable SPA navigation without page reloads?
10. Summary
Vue Router transforms a Vue app into a full multi-page SPA.<RouterView> renders the current page's component. <RouterLink> navigates without reloads. useRouter enables programmatic navigation. useRoute reads current params and query strings. Lazy loading routes ensures fast initial load by splitting code.