{"id":30919000,"url":"https://github.com/cisstech/angular-routing-ux","last_synced_at":"2025-10-27T15:49:09.475Z","repository":{"id":310576241,"uuid":"1040402629","full_name":"cisstech/angular-routing-ux","owner":"cisstech","description":"A demonstration of modern Angular routing patterns that prioritize user experience over traditional blocking guards.","archived":false,"fork":false,"pushed_at":"2025-08-18T23:52:21.000Z","size":109,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-10T02:39:52.322Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cisstech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-18T23:36:42.000Z","updated_at":"2025-08-18T23:52:24.000Z","dependencies_parsed_at":"2025-08-19T01:34:25.094Z","dependency_job_id":null,"html_url":"https://github.com/cisstech/angular-routing-ux","commit_stats":null,"previous_names":["cisstech/angular-routing-ux"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cisstech/angular-routing-ux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisstech%2Fangular-routing-ux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisstech%2Fangular-routing-ux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisstech%2Fangular-routing-ux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisstech%2Fangular-routing-ux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cisstech","download_url":"https://codeload.github.com/cisstech/angular-routing-ux/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cisstech%2Fangular-routing-ux/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281295816,"owners_count":26476759,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-10T00:58:21.878Z","updated_at":"2025-10-27T15:49:09.469Z","avatar_url":"https://github.com/cisstech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Angular routing guards demo\n\nA demonstration of modern Angular routing patterns that prioritize user experience over traditional blocking guards. This project showcases two UX-friendly alternatives to conventional guards that block navigation until authentication is resolved.\n\nLive demo available at : \u003chttps://cisstech.github.io/angular-routing-ux/\u003e\n\n## Project structure\n\nThis demo follows modern Angular practices with a flat file structure and no suffix naming convention:\n\n```txt\nsrc/app/\n├── components/\n│   ├── index.ts         # barrel export\n│   └── skeleton.ts      # reusable skeleton component\n├── directives/\n│   ├── index.ts         # barrel export  \n│   └── auth-if.ts       # structural directive for auth control\n├── guards/\n│   └── auth-guard.ts    # guard implementations\n├── pages/\n│   ├── demo-auth-if.ts  # authIf directive demonstration\n│   ├── demo-blocking.ts # traditional blocking guard demo\n│   ├── demo-skeleton.ts # skeleton guard demonstration\n│   ├── home.ts          # application home page\n│   └── login.ts         # login simulation page\n├── services/\n│   ├── index.ts         # barrel export\n│   ├── auth-guard.ts    # guard state management service\n│   ├── auth.ts          # authentication service\n│   └── user-api.ts      # user data service\n├── app.ts               # root component\n├── app.config.ts        # application configuration\n└── app.routes.ts        # routing configuration\n```\n\n## Modern Angular conventions\n\nThis project demonstrates current Angular best practices:\n\n- **No suffix naming**: Files are named `auth.ts`, `skeleton.ts` instead of `auth.service.ts`, `skeleton.component.ts`\n- **Barrel exports**: Each directory has an `index.ts` for clean imports\n- **Standalone components**: No NgModules, all components are standalone\n- **Signals**: State management uses signals instead of RxJS subjects\n\n## Code simplification for demo purpose\n\n- **Inline templates and styles**: Simplified code with no external CSS/HTML files\n- **Global CSS sharing**: Common styles defined once and reused across components\n\n## Traditional guards limitations\n\nAngular's traditional route guards (`CanActivate`) have significant UX drawbacks:\n\n- **Blocking navigation**: Users see nothing while authentication resolves\n- **Poor performance metrics**: First Contentful Paint is delayed\n- **No visual feedback**: Applications appear frozen during guard execution\n- **Lighthouse score impact**: Core Web Vitals suffer from delayed rendering\n\n```typescript\n// Traditional blocking guard - blocks until resolved\nexport const blockingAuthGuard: CanActivateFn = () =\u003e {\n  const authService = inject(Auth);\n  const router = inject(Router);\n  \n  return authService.loginStatusChange.pipe(\n    map(isLoggedIn =\u003e {\n      if (!isLoggedIn) {\n        router.navigate(['/login']);\n        return false;\n      }\n      return true;\n    })\n  );\n};\n```\n\n## Solution 1: Skeleton guard\n\nThe skeleton guard allows immediate page rendering with placeholder content while authentication resolves in the background.\n\n### Implementation\n\n```typescript\nexport const skeletonAuthGuard: CanActivateFn = (route) =\u003e {\n  const authService = inject(Auth);\n  const userService = inject(UserApi);\n  const router = inject(Router);\n  const guardService = inject(AuthGuard);\n  \n  const skeleton = route.data['skeleton'];\n  const skeletonDelay = route.data['skeletonDelay'] || 300;\n  \n  // Show skeleton after delay if guard is still resolving\n  const skeletonTimer = timer(skeletonDelay).pipe(\n    takeUntil(authService.loginStatusChange),\n    tap(() =\u003e guardService.setSkeleton(skeleton))\n  );\n  \n  return authService.loginStatusChange.pipe(\n    tap(() =\u003e skeletonTimer.subscribe()),\n    mergeMap(isLoggedIn =\u003e {\n      if (!isLoggedIn) {\n        router.navigate(['/login']);\n        return of(false);\n      }\n      \n      return userService.loadCurrentUser().pipe(\n        map(() =\u003e true),\n        catchError(() =\u003e {\n          router.navigate(['/login']);\n          return of(false);\n        })\n      );\n    }),\n    finalize(() =\u003e guardService.setSkeleton(null))\n  );\n};\n```\n\n### Configuration\n\nGuards are configured in route data:\n\n```typescript\n{\n  path: 'protected',\n  component: ProtectedPage,\n  canActivate: [skeletonAuthGuard],\n  data: {\n    skeleton: SkeletonOverlay,\n    skeletonDelay: 300  // milliseconds\n  }\n}\n```\n\n### Use cases\n\n- **Dashboard pages**: Show layout skeleton while loading user data\n- **Profile sections**: Display structure while fetching user information  \n- **Data-heavy pages**: Provide visual feedback during authentication and data loading\n- **Mobile applications**: Improve perceived performance on slower connections\n\n### Limitations\n\n- **Layout matching**: Skeleton must exactly match final page layout to avoid layout shifts\n- **Maintenance overhead**: Skeleton components need updates when page layout changes\n- **Content complexity**: Not suitable for highly dynamic content structures\n- **Animation considerations**: Skeleton transitions should be smooth to avoid jarring effects\n\n### Skeleton techniques\n\nThe skeleton system uses shared CSS between host and overlay components:\n\n```typescript\n@Component({\n  selector: 'app-skeleton',\n  template: `\n    \u003cdiv\n      class=\"skeleton\"\n      [class]=\"'skeleton--' + variant()\"\n      [style.width]=\"width() || undefined\"\n      [style.height]=\"height() || undefined\"\n    \u003e\u003c/div\u003e\n  `,\n  styles: [`\n    .skeleton {\n      background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);\n      background-size: 200% 100%;\n      animation: skeleton-shimmer 1.5s ease-in-out infinite;\n    }\n  `]\n})\nexport class Skeleton {\n  variant = input\u003c'line' | 'text' | 'card' | 'button'\u003e('line');\n  width = input\u003cstring\u003e();     // explicit width prevents layout shifts\n  height = input\u003cstring\u003e();    // explicit height maintains space\n}\n```\n\n**skeletonDelay property**: Controls when skeleton appears (default: 300ms). This prevents skeleton flash on fast connections while providing feedback on slower ones.\n\n## Solution 2: AuthIf directive\n\nA structural directive that provides granular authentication control without navigation blocking.\n\n### Implementation\n\n```typescript\n@Directive({\n  selector: '[authIf]',\n  standalone: true\n})\nexport class AuthIf {}\n```\n\n### Usage\n\n```html\n\u003cdiv *authIf=\"let authState = state; let user = user; redirectOnReject: false; onAccept: onLoadUser.bind(this)\"\u003e\n  @switch (authState) {\n    @case ('pending') {\n      \u003capp-skeleton variant=\"card\"\u003e\u003c/app-skeleton\u003e\n    }\n    @case ('accepted') {\n      \u003ch1\u003eWelcome {{ user?.name }}\u003c/h1\u003e\n    }\n    @case ('denied') {\n      \u003cp\u003ePlease log in to continue\u003c/p\u003e\n    }\n  }\n\u003c/div\u003e\n```\n\n```txt\nclass MyComponent {\n\n  onLoadUser(user) {\n    // replace ngOnInit\n  }\n}\n```\n\n### Properties\n\n- **authIfOnAccept**: Callback to intercept user resolving\n- **authIfOnReject**: Callback to intercept errors\n- **authIfRedirectOnReject**: Automatically redirects to login when authentication fails (default: true)\n- **state**: Provides current authentication state (`pending`, `accepted`, `denied`)\n- **user**: Exposes current user data when authenticated\n\n\u003e This directive can be upgraded to accept roles and check more options on user.\n\n### Use cases\n\n- **Mixed content pages**: Combine public and protected content on the same page\n- **Progressive disclosure**: Show different content based on user permissions\n- **Granular control**: Apply authentication logic to specific page sections\n- **Complex layouts**: Handle multiple authentication zones independently\n\n### Comparison table\n\n| Approach | Navigation blocking | First paint | UX impact | Complexity | Use case |\n|----------|-------------------|-------------|-----------|------------|----------|\n| Traditional guard | Yes | Delayed | Poor | Low | Simple auth check |\n| Skeleton guard | No | Immediate | Good | Medium | Full page protection |\n| AuthIf directive | No | Immediate | Excellent | Low | Granular control |\n\n## Running the demo\n\n```bash\nnpm install\nnpm run start\n```\n\nNavigate to `http://localhost:4200` to explore the different approaches.\n\n## Technical considerations\n\n- **Performance**: Skeleton and AuthIf approaches improve Core Web Vitals scores\n- **Accessibility**: Skeleton animations should respect `prefers-reduced-motion`\n- **SEO**: Immediate page rendering improves search engine indexing\n- **Analytics**: Better user engagement metrics due to faster perceived loading\n\nThis demo intentionally keeps code simple with inline templates and styles to focus on the core concepts rather than project structure complexity.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcisstech%2Fangular-routing-ux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcisstech%2Fangular-routing-ux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcisstech%2Fangular-routing-ux/lists"}