有我的应用路由模块
const routes: Routes = [
{ path: 'public', loadChildren: 'app/public/public.module#PublicModule' },
{ path: 'crm', loadChildren: 'app/crm/crm.module#CrmModule', canActivate: [AuthGuard] },
{ path: '', redirectTo: '/public', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { enableTracing: true })],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
App模块
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
公共路由模块
const routes: Routes = [
{ path: '', redirectTo: 'feed' },
{
path: 'feed', component: Public.PublicHostComponent, children: [
{ path: 'sign-up', component: Public.SignUpComponent, outlet: 'signUpPopup' },
{ path: '', component: Public.PublicMainComponent }
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: []
})
export class PublicRoutingModule { }
PublicHostComponent只是一个包含下一个
的包装器<router-outlet></router-outlet>
<router-outlet name="signUpPopup"></router-outlet>
接下来是问题所在。
当我转到root localhost:4200
时,它会将我重定向到localhost:4200/public
,而且只有空白页面,但是当我输入localhost:4200/public
时,它会将我重定向到正确的路线({ {1}})。
这种行为的原因是什么?
修改
当我从此行localhost:4200/public/feed
('/public' => 'public')
在应用路由模块中,路由开始按预期工作。