⚔️ 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
| Feature | Citadel | route-guard | router-shield | easy-route | programic |
|---|---|---|---|---|---|
| TypeScript (native) | ✅ | ✅ | ❌ | ✅ | ✅ |
| Return-based API | ✅ | ❌ | ❌ | ❌ | ❌ |
| Dynamic management | ✅ | ❌ | ❌ | ❌ | ❌ |
| Multiple hooks | 3 | 1 | 1 | 1 | 2 |
| 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.
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.
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.
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.
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 hooks —
beforeEach,beforeResolve, andafterEachsupport - 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/onTimeouthandlers 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.