Angular child route and 404

只愿长相守 提交于 2019-12-11 03:13:17

问题


The route to find nonexistent links does not allow you to go through child links.

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { IntroComponent } from './shared/components/intro/intro.component';
import { NotFoundComponent } from './shared/components/not-found/not-found.component';
import { ReportsComponent } from './reports/reports.component';
import { TrainingComponent } from './training/training.component';
import { TmComponent } from './tm/tm.component';

const routes: Routes = [
  { path: '', component: IntroComponent },
  { path: 'reports', component: ReportsComponent },
  { path: 'training', component: TrainingComponent },
  { path: 'tm', component: TmComponent },
  { path: '**', component: NotFoundComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

training-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { TrainingComponent } from './training.component';
import { ViewComponent } from './scenario/view/view.component';
import { EditorComponent } from './scenario/editor/editor.component';
import { ListComponent } from './scenario/list/list.component';

const routes: Routes = [
  {
    path: 'training', component: TrainingComponent, children: [
      { path: 'scenarios', component: ListComponent },
      { path: 'scenario/view/:id', component: ViewComponent },
      { path: 'scenario/editor/:id', component: EditorComponent }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class TrainingRoutingModule { }

If you delete the route { path: '**', component: NotFoundComponent }, the links work. But 404 error is not processed.

Tell me, please, how to make these routes work with processing 404 errors?

来源:https://stackoverflow.com/questions/51059345/angular-child-route-and-404

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!