Differenzansicht 14-lazyloading
im Vergleich zu 13-search

Zurück zur Übersicht | ← Vorherige | Nächste → | Demo | Quelltext auf GitHub
src/app/app.routes.ts CHANGED
@@ -1,12 +1,21 @@
1
  import { Routes } from '@angular/router';
2
 
3
- import { HomePage } from './home-page/home-page';
4
- import { booksPortalRoutes } from './books-portal/books-portal.routes';
5
- import { booksAdminRoutes } from './books-admin/books-admin.routes';
6
-
7
  export const routes: Routes = [
8
  { path: '', redirectTo: 'home', pathMatch: 'full' },
9
- { path: 'home', component: HomePage, title: 'BookManager' },
10
- ...booksPortalRoutes,
11
- ...booksAdminRoutes
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ];
 
1
  import { Routes } from '@angular/router';
2
 
 
 
 
 
3
  export const routes: Routes = [
4
  { path: '', redirectTo: 'home', pathMatch: 'full' },
5
+ {
6
+ path: 'home',
7
+ title: 'BookManager',
8
+ loadComponent: () => import('./home-page/home-page')
9
+ .then(m => m.HomePage)
10
+ },
11
+ {
12
+ path: 'books',
13
+ loadChildren: () => import('./books-portal/books-portal.routes')
14
+ .then(m => m.booksPortalRoutes)
15
+ },
16
+ {
17
+ path: 'admin',
18
+ loadChildren: () => import('./books-admin/books-admin.routes')
19
+ .then(m => m.booksAdminRoutes)
20
+ }
21
  ];
src/app/books-admin/books-admin.routes.ts CHANGED
@@ -3,6 +3,6 @@ import { Routes } from '@angular/router';
3
  import { BookCreatePage } from './book-create-page/book-create-page';
4
 
5
  export const booksAdminRoutes: Routes = [
6
- { path: 'admin', redirectTo: 'admin/create' },
7
- { path: 'admin/create', component: BookCreatePage, title: 'Create Book' }
8
  ];
 
3
  import { BookCreatePage } from './book-create-page/book-create-page';
4
 
5
  export const booksAdminRoutes: Routes = [
6
+ { path: '', redirectTo: 'create', pathMatch: 'full' },
7
+ { path: 'create', component: BookCreatePage, title: 'Create Book' }
8
  ];
src/app/books-portal/book-details-page/book-details-page.spec.ts CHANGED
@@ -61,9 +61,9 @@ describe('BookDetailsPage', () => {
61
  const location = TestBed.inject(Location);
62
  const router = TestBed.inject(Router);
63
 
64
- await router.navigate(['/books/details/12345']);
65
 
66
- expect(location.path()).toBe('/books/details/12345');
67
  });
68
 
69
  it('should update the book when ISBN changes', async () => {
 
61
  const location = TestBed.inject(Location);
62
  const router = TestBed.inject(Router);
63
 
64
+ await router.navigate(['/details/12345']);
65
 
66
+ expect(location.path()).toBe('/details/12345');
67
  });
68
 
69
  it('should update the book when ISBN changes', async () => {
src/app/books-portal/books-overview-page/books-overview-page.spec.ts CHANGED
@@ -85,7 +85,7 @@ describe('BooksOverviewPage', () => {
85
 
86
  it('should load the BooksOverviewPage for /books', async () => {
87
  const harness = await RouterTestingHarness.create();
88
- const component = await harness.navigateByUrl('/books', BooksOverviewPage);
89
 
90
  expect(component).toBeTruthy();
91
  expect(document.title).toBe('Books');
 
85
 
86
  it('should load the BooksOverviewPage for /books', async () => {
87
  const harness = await RouterTestingHarness.create();
88
+ const component = await harness.navigateByUrl('/', BooksOverviewPage);
89
 
90
  expect(component).toBeTruthy();
91
  expect(document.title).toBe('Books');
src/app/books-portal/books-portal.routes.ts CHANGED
@@ -4,6 +4,6 @@ import { BooksOverviewPage } from './books-overview-page/books-overview-page';
4
  import { BookDetailsPage } from './book-details-page/book-details-page';
5
 
6
  export const booksPortalRoutes: Routes = [
7
- { path: 'books', component: BooksOverviewPage, title: 'Books' },
8
- { path: 'books/details/:isbn', component: BookDetailsPage, title: 'Book Details' },
9
  ];
 
4
  import { BookDetailsPage } from './book-details-page/book-details-page';
5
 
6
  export const booksPortalRoutes: Routes = [
7
+ { path: '', component: BooksOverviewPage, title: 'Books' },
8
+ { path: 'details/:isbn', component: BookDetailsPage, title: 'Book Details' },
9
  ];