Route a Vue app with guards and lazy-loaded pages

8 steps · about 1 h 45 min · Intermediate

  1. Add Vue Router to an app (tutorial, Vue Router, 15 min)

    Sets up the router, RouterView and RouterLink from scratch.

  2. Match dynamic segments like /users/:id (reference, Vue Router, 15 min)

    Explains params, catch-all routes and reacting to param changes.

  3. Nest child routes inside layouts (reference, Vue Router, 10 min)

    Shows nested RouterView for dashboards and settings pages.

  4. Navigate in code with push and replace (reference, Vue Router, 10 min)

    Covers programmatic navigation and history control.

  5. Protect pages with navigation guards (reference, Vue Router, 20 min)

    Global, per-route and in-component guards for login checks.

  6. 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.

  7. Split each page into its own chunk (reference, Vue Router, 10 min)

    Keeps the first download small with dynamic imports.

  8. Choose history mode and configure the server (reference, Vue Router, 15 min)

    Avoids 404s on refresh with HTML5 history and server fallbacks.