没有RouterOutletMap的提供程序 最新Angular 2.0.0,并通过最新Angular cli 1.0.0-beta.14,节点:6.6.0,操作系统:linux x64 我所做的:
1) 创建新项目没有RouterOutletMap的提供程序 最新Angular 2.0.0,并通过最新Angular cli 1.0.0-beta.14,节点:6.6.0,操作系统:linux x64 我所做的:,angular,Angular,1) 创建新项目 ng new angular-test ng g component projects ng g component typings 2) 添加简单路由 /src/app/app.component.html <router-outlet></router-outlet> 我得到的是: 我是如何试图解决这个问题的 我试图将RouterOutletMap添加到AppModule中的提供程序中,但应用程序不重定向到项目,也不显示嵌套组件您需要为应用程
ng new angular-test
ng g component projects
ng g component typings
2) 添加简单路由
/src/app/app.component.html
<router-outlet></router-outlet>
我得到的是:
我是如何试图解决这个问题的
我试图将RouterOutletMap添加到AppModule中的提供程序中,但应用程序不重定向到项目,也不显示嵌套组件您需要为应用程序模块调用
RouterModule.forRoot
,而不是forChild
。前者,而后者。对于子模块,您应该使用forChild
,而不是app模块。我也遇到了这个问题,并且。这就是我如何避免。。。。。总有一天这会有所帮助。
致以最良好的祝愿
路由数组--app.routes.ts
const appRoutes:Routes =[
{
path: 'home',
component: CarouselComponent
},
{
path: 'profile',
component:UserDashboardComponentComponent,
children: [
{
path: 'overview',
component: ProfileOverviewComponent
},
{
path: 'post',
component: PostAddComponent
}
]
}
];
export const WebRouting: ModuleWithProviders =RouterModule.forRoot(appRoutes);
@NgModule({
declarations: [
AppComponent,
CarouselComponent,
.......
],
imports: [
BrowserModule,
MdTabsModule,
MaterialModule,
MdInputModule,
BrowserAnimationsModule,
FormsModule,
HttpModule,
WebRouting
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule { }
应用程序模块.ts
const appRoutes:Routes =[
{
path: 'home',
component: CarouselComponent
},
{
path: 'profile',
component:UserDashboardComponentComponent,
children: [
{
path: 'overview',
component: ProfileOverviewComponent
},
{
path: 'post',
component: PostAddComponent
}
]
}
];
export const WebRouting: ModuleWithProviders =RouterModule.forRoot(appRoutes);
@NgModule({
declarations: [
AppComponent,
CarouselComponent,
.......
],
imports: [
BrowserModule,
MdTabsModule,
MaterialModule,
MdInputModule,
BrowserAnimationsModule,
FormsModule,
HttpModule,
WebRouting
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule { }
tempale.html
<li>
<a [routerLink]="['/profile/overview']" routerLinkActive="active" >
Overview
</a>
</li>
<li>
<a [routerLink]="['/profile/post']"routerLinkActive="active">
PostAdd
</a>
</li>
概述
邮递
Hi我遇到了同样的问题,我使用了.forRoot
。介意看一下吗?