diff --git a/modules/@angular/router/src/common_router_providers.ts b/modules/@angular/router/src/common_router_providers.ts index 63bd4b470b..1c408170eb 100644 --- a/modules/@angular/router/src/common_router_providers.ts +++ b/modules/@angular/router/src/common_router_providers.ts @@ -7,7 +7,7 @@ */ import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common'; -import {APP_INITIALIZER, AppModuleFactoryLoader, ApplicationRef, ComponentResolver, Injector, OpaqueToken, SystemJsAppModuleLoader} from '@angular/core'; +import {ANALYZE_FOR_PRECOMPILE, APP_INITIALIZER, AppModuleFactoryLoader, ApplicationRef, ComponentResolver, Injector, OpaqueToken, SystemJsAppModuleLoader} from '@angular/core'; import {Routes} from './config'; import {Router} from './router'; @@ -84,6 +84,7 @@ export function setupRouterInitializer(injector: Injector) { */ export function provideRouter(routes: Routes, config: ExtraOptions): any[] { return [ + {provide: ANALYZE_FOR_PRECOMPILE, multi: true, useValue: routes}, {provide: ROUTES, useExisting: ROUTER_CONFIG}, {provide: ROUTER_CONFIG, useValue: routes}, {provide: ROUTER_CONFIGURATION, useValue: config}, Location, @@ -125,7 +126,10 @@ export function provideRouter(routes: Routes, config: ExtraOptions): any[] { * @experimental */ export function provideRoutes(routes: Routes): any { - return {provide: ROUTES, useValue: routes}; + return [ + {provide: ANALYZE_FOR_PRECOMPILE, multi: true, useValue: routes}, + {provide: ROUTES, useValue: routes} + ]; } /** diff --git a/modules/@angular/router/src/directives/router_outlet.ts b/modules/@angular/router/src/directives/router_outlet.ts index 9d3d02f431..4d65a7dcab 100644 --- a/modules/@angular/router/src/directives/router_outlet.ts +++ b/modules/@angular/router/src/directives/router_outlet.ts @@ -74,15 +74,12 @@ export class RouterOutlet { } } catch (e) { if (!(e instanceof NoComponentFactoryError)) throw e; - - // TODO: vsavkin uncomment this once ComponentResolver is deprecated - // const componentName = component ? component.name : null; - // console.warn( - // `'${componentName}' not found in precompile array. To ensure all components referred - // to by the Routes are compiled, you must add '${componentName}' to the - // 'precompile' array of your application component. This will be required in a future - // release of the router.`); - + const componentName = component ? component.name : null; + console.warn( + `'${componentName}' not found in precompile array. To ensure all components referred + to by the Routes are compiled, you must add '${componentName}' to the + 'precompile' array of your application component. This will be required in a future + release of the router.`); factory = snapshot._resolvedComponentFactory; } diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index 5897cdb6a9..f6a43166ed 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -36,15 +36,6 @@ describe('Integration', () => { (router: Router, tcb: TestComponentBuilder, location: Location) => { const fixture = createRoot(tcb, router, RootCmp); - @Component({ - selector: 'child', - template: '
', - directives: ROUTER_DIRECTIVES - }) - class LinkInNgIf { - alwaysTrue = true; - } - router.resetConfig([{ path: 'child', component: LinkInNgIf, @@ -1303,6 +1294,15 @@ class RelativeLinkInIfCmp { show: boolean = false; } +@Component({ + selector: 'child', + template: '
', + directives: ROUTER_DIRECTIVES +}) +class LinkInNgIf { + alwaysTrue = true; +} + @Component({ selector: 'root-cmp', template: ``, @@ -1310,7 +1310,7 @@ class RelativeLinkInIfCmp { precompile: [ BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp, RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp, - QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp + QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp, LinkInNgIf ] }) class RootCmp { diff --git a/modules/playground/src/routing/app/inbox-app.ts b/modules/playground/src/routing/app/inbox-app.ts index b66016dc73..ba98bbc638 100644 --- a/modules/playground/src/routing/app/inbox-app.ts +++ b/modules/playground/src/routing/app/inbox-app.ts @@ -140,7 +140,6 @@ export const ROUTER_CONFIG = [ selector: 'inbox-app', viewProviders: [DbService], templateUrl: 'app/inbox-app.html', - directives: ROUTER_DIRECTIVES, - precompile: [InboxCmp, DraftsCmp] + directives: ROUTER_DIRECTIVES }) export class InboxApp {} diff --git a/modules/playground/src/routing/app/inbox-detail.ts b/modules/playground/src/routing/app/inbox-detail.ts index 681c31e3da..d0780b8d59 100644 --- a/modules/playground/src/routing/app/inbox-detail.ts +++ b/modules/playground/src/routing/app/inbox-detail.ts @@ -25,7 +25,6 @@ export class InboxDetailCmp { } @AppModule({ - providers: [provideRoutes([{path: ':id', component: InboxDetailCmp}])], - precompile: [InboxDetailCmp] + providers: [provideRoutes([{path: ':id', component: InboxDetailCmp}])] }) export default class InboxDetailModule {} \ No newline at end of file