Route a Vue app with guards and lazy-loaded pages
8 steps · about 1 h 45 min · Intermediate
- Add Vue Router to an app (tutorial, Vue Router, 15 min)
Sets up the router, RouterView and RouterLink from scratch.
- Match dynamic segments like /users/:id (reference, Vue Router, 15 min)
Explains params, catch-all routes and reacting to param changes.
- Nest child routes inside layouts (reference, Vue Router, 10 min)
Shows nested RouterView for dashboards and settings pages.
- Navigate in code with push and replace (reference, Vue Router, 10 min)
Covers programmatic navigation and history control.
- Protect pages with navigation guards (reference, Vue Router, 20 min)
Global, per-route and in-component guards for login checks.
- Mark routes with meta fields such as requiresAuth (reference, Vue Router, 10 min)
Lets one guard read per-route rules instead of hard-coding paths.
- Split each page into its own chunk (reference, Vue Router, 10 min)
Keeps the first download small with dynamic imports.
- Choose history mode and configure the server (reference, Vue Router, 15 min)
Avoids 404s on refresh with HTML5 history and server fallbacks.