BookMonkey 4 Diff

Files changed (3) hide show
  1. tmp/src/app/book-monkey/iteration-6/{lazy-loading → guards}/app-routing.module.ts +5 -3
  2. tmp/src/app/book-monkey/iteration-6/{lazy-loading → guards}/books/book-list/book-list.component.html +1 -1
  3. tmp/src/app/book-monkey/iteration-6/{lazy-loading → guards}/can-navigate-to-admin.guard.ts +17 -0
tmp/src/app/book-monkey/iteration-6/{lazy-loading → guards}/app-routing.module.ts RENAMED
@@ -1,7 +1,8 @@
1
  import { NgModule } from '@angular/core';
2
- import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
3
   
4
  import { HomeComponent } from './home/home.component';
   
5
   
6
  export const routes: Routes = [
7
  {
@@ -15,11 +16,12 @@
15
  },
16
  {
17
  path: 'books',
18
- loadChildren: () => import('src/app/book-monkey/iteration-6/lazy-loading/books/books.module').then(m => m.BooksModule)
19
  },
20
  {
21
  path: 'admin',
22
- loadChildren: () => import('src/app/book-monkey/iteration-6/lazy-loading/admin/admin.module').then(m => m.AdminModule)
   
23
  }
24
  ];
25
   
1
  import { NgModule } from '@angular/core';
2
+ import { Routes, RouterModule } from '@angular/router';
3
   
4
  import { HomeComponent } from './home/home.component';
5
+ import { CanNavigateToAdminGuard } from './can-navigate-to-admin.guard';
6
   
7
  export const routes: Routes = [
8
  {
16
  },
17
  {
18
  path: 'books',
19
+ loadChildren: () => import('src/app/book-monkey/iteration-6/guards/books/books.module').then(m => m.BooksModule)
20
  },
21
  {
22
  path: 'admin',
23
+ loadChildren: () => import('src/app/book-monkey/iteration-6/guards/admin/admin.module').then(m => m.AdminModule),
24
+ canActivate: [CanNavigateToAdminGuard]
25
  }
26
  ];
27
   
tmp/src/app/book-monkey/iteration-6/{lazy-loading → guards}/books/book-list/book-list.component.html RENAMED
@@ -16,4 +16,4 @@
16
  </ng-template>
17
   
18
  </div>
19
-
16
  </ng-template>
17
   
18
  </div>
19
+
tmp/src/app/book-monkey/iteration-6/{lazy-loading → guards}/can-navigate-to-admin.guard.ts RENAMED
@@ -0,0 +1,17 @@
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
1
+ import { Injectable } from '@angular/core';
2
+ import { CanActivate } from '@angular/router';
3
+  
4
+ @Injectable({
5
+ providedIn: 'root'
6
+ })
7
+ export class CanNavigateToAdminGuard implements CanActivate {
8
+
9
+ accessGranted = false;
10
+  
11
+ canActivate(): boolean {
12
+ if (!this.accessGranted) {
13
+ this.accessGranted = window.confirm('Mit großer Macht kommt große Verantwortung. Möchten Sie den Admin-Bereich betreten?');
14
+ }
15
+ return this.accessGranted;
16
+ }
17
+ }