wouter-vue Documentation

Route Guards

Implement route protection using Vue’s reactivity system and watchers.

Global Route Guard

Watch location changes and redirect based on authentication:

Protected Route Component

Create a reusable wrapper component:

ProtectedRoute.vue:

Alternative with Conditional Rendering

Notes

  • Use watch to monitor location changes
  • Use Redirect component for programmatic redirects
  • Combine with useRouteData() for route-specific permissions
  • See Hierarchical Data Passing for passing permissions through routes

Built with wouter-vue • GitHub