|
11 | 11 | import '@angular/compiler';
|
12 | 12 | /* eslint-enable import/no-unassigned-import */
|
13 | 13 |
|
14 |
| -import { Component } from '@angular/core'; |
15 |
| -import { Routes, provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router'; |
| 14 | +import { Component, InjectionToken, Injector, inject } from '@angular/core'; |
| 15 | +import { |
| 16 | + Route, |
| 17 | + Routes, |
| 18 | + provideRouter, |
| 19 | + withEnabledBlockingInitialNavigation, |
| 20 | +} from '@angular/router'; |
16 | 21 | import { extractRoutesAndCreateRouteTree } from '../../src/routes/ng-routes';
|
17 | 22 | import { PrerenderFallback, RenderMode } from '../../src/routes/route-config';
|
18 | 23 | import { setAngularAppTestingManifest } from '../testing-utils';
|
@@ -717,4 +722,36 @@ describe('extractRoutesAndCreateRouteTree', () => {
|
717 | 722 | { route: '/**', renderMode: RenderMode.Server },
|
718 | 723 | ]);
|
719 | 724 | });
|
| 725 | + |
| 726 | + it(`should create and run route level injector when 'loadChildren' is used`, async () => { |
| 727 | + const ChildRoutes = new InjectionToken<Route[]>('Child Routes'); |
| 728 | + setAngularAppTestingManifest( |
| 729 | + [ |
| 730 | + { |
| 731 | + path: '', |
| 732 | + component: DummyComponent, |
| 733 | + providers: [ |
| 734 | + { |
| 735 | + provide: ChildRoutes, |
| 736 | + useValue: [ |
| 737 | + { |
| 738 | + path: 'home', |
| 739 | + component: DummyComponent, |
| 740 | + }, |
| 741 | + ], |
| 742 | + }, |
| 743 | + ], |
| 744 | + loadChildren: () => inject(ChildRoutes), |
| 745 | + }, |
| 746 | + ], |
| 747 | + [{ path: '**', renderMode: RenderMode.Server }], |
| 748 | + ); |
| 749 | + |
| 750 | + const { routeTree, errors } = await extractRoutesAndCreateRouteTree({ url }); |
| 751 | + expect(errors).toHaveSize(0); |
| 752 | + expect(routeTree.toObject()).toEqual([ |
| 753 | + { route: '/', renderMode: RenderMode.Server }, |
| 754 | + { route: '/home', renderMode: RenderMode.Server }, |
| 755 | + ]); |
| 756 | + }); |
720 | 757 | });
|
0 commit comments