当路由配置包含一些共享的静态数据时,在AOT编译期间将忽略这些数据。但是,它可以与JIT编译器一起正常工作。
data: {
trackingArea: 'some-feature',
product: 'some-feature'
}
};
// `data` property will not be present with AOT
const routes: Routes = [
{ path: '', pathMatch: 'full', component: HomeComponent, ...sharedConfig },
{ path: '**', component: NotFoundComponent, ...sharedConfig }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
答案 0 :(得分:0)
为路由配置提供共享静态数据组的预期方法是为其提供单独的接口或类文件。
export class SharedData{
public static readonly trackingArea = 'some-feature';
public static readonly product = 'some-feature';
}
如果您的要求是传递动态数据,则这是一个已经回答的问题: Passing dynamic data through Angular 2 route