Adi99 Adi99 - 3 months ago 51
TypeScript Question

How to handle precompile array warning using simple router in angular2

I am trying to create simple router based application in Angular2 using typescript. My Angular2 version is

2.0.0-rc.4
and router version is
3.0.0-beta.1


My Routes configuration follows-

App.routes.ts

import { provideRouter, RouterConfig } from '@angular/router';
import { PageNotFoundComponent } from './Shared/pageNotFound.component';
import { Page1Component } from './Pages/Page1/page1.component';
import { Page2Component } from './Pages/Page2/page2.component';

const routes: RouterConfig = [

{ path: 'page1', component: Page1Component },
{ path: 'page2', component: Page2Component },
{ path: '**', component: PageNotFoundComponent }
];

export const appRouterProviders = [
provideRouter(routes)
];


While running application using npm start command I receives one warning (not error). Please refer this screen shot for warning

How do I overcome this warning?

Answer

Try adding below line in your main AppComponent-

  precompile: [Page1Component, Page2Component .... ]

See if this helps.

Comments