使用子路由:错误错误:未捕获(承诺):错误:无法匹配任何路由。 URL段

时间:2020-05-24 16:57:01

标签: angular parent-child router

我收到此错误,却不知道为什么。我希望你能帮助我。 我用“ Localhost:4200 / Admin / Lastrecords”调用了URL。

错误错误:未捕获(承诺):错误:无法匹配任何路由。 URL段。“最后记录”

parent.module

@NgModule({
  declarations: [
    AppComponent,
    InfoComponent,
    LoginComponent,
    ProtectedComponent,
    DropdownDirective,
    MainComponent
  ],
  imports: [
    BrowserModule,
    routing,],
    ...
    export class AppModule { }

parent.router

const APP_ROUTES: Routes = [
    {path: '', component: LoginComponent},
    {path: 'Admin', component: DashboardComponent, loadChildren: './admin/admin.module#AdminModule'},
];

export const routing = RouterModule.forRoot(APP_ROUTES);

child.module

@NgModule({
  declarations: [
    DashboardComponent,
    NewAccComponent,
    KeyComponent,
    LastLoginComponent,
    RecordComponent
  ],
  imports: [
    routdash,
    FormsModule,
  ],

   export class AdminModule {

}

child.routing

const DASH_ROUTES: Routes = [
  {path: '', component: LastLoginComponent, outlet: 'sec'},
  {path: 'Lastlogins', component: LastLoginComponent, outlet: 'sec'},
  {path: 'Lastrecords', component: RecordComponent, outlet: 'sec'},
];

export const routdash = RouterModule.forChild(DASH_ROUTES);

1 个答案:

答案 0 :(得分:1)

之所以不起作用,是因为您在子路由('sec')中指定了(辅助)出口,因此URL应如下所示:

http://localhost:4200/Admin(sec:Lastrecords)

更多信息:

https://angular.io/guide/router#secondary-routes