12-route-guards

Implement session-aware route guards for SPA navigation with role-based access.

Updated Mar 9, 2026
One-click install
npx skills add https://github.com/kennypallchizaca-coder/agentic-full-stack-skills --skill 12-route-guards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 12-route-guards
Source: https://github.com/kennypallchizaca-coder/agentic-full-stack-skills/tree/main/frontend-skills/12-route-guards
Command: npx skills add https://github.com/kennypallchizaca-coder/agentic-full-stack-skills --skill 12-route-guards

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Route navigation in SPAs often breaks when session state is not hydrated, leading to flicker or incorrect access decisions. This Skill provides session-aware guards to enforce authentication, guest access, and role-based routing, waiting for session bootstrap before redirecting.

Core Features & Use Cases

  • Auth guards protect private routes until the session is hydrated.
  • Guest guards prevent authenticated users from visiting login/register pages.
  • Role-based guards secure privileged areas, with optional deactivation guards for unsaved changes.
  • Redirect handling preserves the user's intended destination on login.

Quick Start

Configure your router to load a central auth store and apply require-auth, require-guest, and require-role guards using route metadata.

Frequently Asked Questions about 12-route-guards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SPA route guards from flickering or incorrectly redirecting before the session is hydrated?

Session-aware route guards wait for session bootstrap before evaluating access, preventing flicker. This ensures the auth store is fully hydrated so route guards apply authentication, guest, and role-based access controls without premature redirects.

How do I configure role-based access control for private routes in a SPA router?

Configure role-based access control by applying require-role guards using route metadata. The guards check the central auth store to secure privileged areas, enforcing role-based routing permissions after the session state is successfully bootstrapped.

How do I redirect authenticated users away from login and register pages?

Apply guest guards to login and register routes to prevent authenticated users from accessing them. The guard checks the central auth store and redirects logged-in users away from guest-only screens once the session is active.

How do I preserve a user's intended destination URL when redirecting them to login?

Redirect handling preserves the user's intended destination URL during route guard redirects. When an auth guard blocks a private route, it saves the return URL so the application can navigate the user back to their original destination after authenticating.

Can I use route guards to prevent users from navigating away from pages with unsaved changes?

Yes, optional deactivation guards can be applied to prevent navigation away from pages with unsaved changes. These route guards intercept routing events to secure privileged areas and protect against accidental data loss during session-aware navigation.

Why does my frontend routing allow unauthorized access even with route guards in place?

Frontend routing allows unauthorized access when route guards evaluate before the session is hydrated. Implementing session-aware guards that wait for session bootstrap ensures the central auth store is fully loaded before enforcing authentication and role-based access controls.