Skip to content

⚔️ Comparison

Vue Router provides built-in navigation guards (beforeEach, beforeResolve, afterEach), but as applications grow, managing multiple guards becomes complex. Several libraries attempt to solve this problem. Here's how they compare to Vue Router Citadel.

📊 Feature Matrix

FeatureCitadelroute-guardrouter-shieldeasy-routeprogramic
TypeScript (native)
Return-based API
Dynamic management
Multiple hooks31112
Global scope
Route scope
Priority ordering
Timeout control
Lazy loading
Type-safe names
Error handling
Vue DevTools
Logging & debug
Bundle size (brotli)≤4 KB~3 KB~1 KB~3 KB~1 KB

📦 Alternatives

@this-dot/vue-route-guard — From This Dot Labs. Declarative authentication guard with token management and permission-based access control. Vue Router 4, TypeScript.

js
setupGuard({
  router,
  token: { name: 'AUTH_TOKEN', storage: StorageType.sessionStorage },
  redirect: { noAuthentication: '/login', noPermission: '/forbidden' },
  options: { fetchAuthentication: () => fetchUser() },
});

// Routes use meta fields:
// { path: '/dashboard', meta: { requiresAuth: true, access: ['admin'] } }

vue-router-shield — Provides BeforeEach, BeforeEnter, and BeforeUpdate guard types within a single beforeEach hook. Guards are defined in route.meta.guard. Plain JavaScript.

js
const route = {
  path: '/profile',
  meta: {
    guard: [new BeforeEach(authMiddleware), new BeforeUpdate(trackMiddleware)],
  },
};

@warhsn/easy-route-vue — Laravel-inspired middleware system. Supports TypeScript and Vue Router 4.

js
const route = {
  path: '/admin',
  meta: {
    middleware: ['auth', 'admin'],
  },
};

@programic/vue-router-middleware — Modern middleware abstraction for Vue Router 4. Built with Vite and vitest. Native TypeScript.

js
const route = {
  path: '/dashboard',
  meta: {
    middleware: [authMiddleware],
  },
};

🏰 Why Citadel?

Vue Router Citadel is designed for applications that outgrow simple guard combinations:

  • Return-based API — no next() callbacks, clean control flow with verdicts
  • Dynamic management — deploy/abandon outposts and assign/revoke to routes at runtime
  • Multiple hooksbeforeEach, beforeResolve, and afterEach support
  • Two scopes — global outposts for app-wide checks, route outposts for page-specific logic
  • Priority ordering — fine-grained control over execution order across all outposts
  • Timeout control — global and per-outpost timeout with custom handlers
  • Lazy loading — dynamic imports for code splitting heavy handlers
  • Type-safe names — declaration merging for compile-time validation and IDE autocomplete
  • Error handling — structured onError / onTimeout handlers with context and custom outcomes
  • Vue DevTools — custom inspector for viewing and debugging deployed outposts
  • Logging & debug — customizable logger, debug breakpoints, runtime log level control
  • ≤4 KB — minimal footprint (minified + brotli)

TIP

See the Getting Started guide to set up your first outpost in under 5 minutes.


Footnote

Of course, you can always write your own middleware system with router.beforeEach and route.meta — it's only about 20 lines of code. Then add error handling, timeouts, priority sorting, scoping, logging, devtools, types... and before you know it, you've written your own library. We've been there. That's why this one exists.

Released under the MIT License.