Angular 4路线问题

时间:2018-05-02 07:35:13

标签: angular routes

当我执行此代码以重定向到其他组件

this.router.navigate(['/distributed-chart/' + this.invested.risk]);

我在控制台中遇到此问题:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL 
Segment: 'distributed-chart/54f9ef8a84d534d9490002d1'

应用-routing.module.ts

const routes: Routes = [
    { path: '', redirectTo: 'simulation/simulate-saving-plan', pathMatch: 'full' },
    { path: 'simulation', loadChildren: 'app/simulation/simulation.module#SimulationModule' },
];

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

模拟-routing.module.ts

const routes: Routes = [
  { path: '', component: SimulationComponent,
  children:[
    { path: 'simulate-saving-plan', component: SimulateSavingPlanComponent },
    { path: 'distributed-chart/:risk', component: DistributedChartComponent },
    { path: 'expected-rent-chart', component: ExpectedRentChartComponent },
    { path: 'historic-chart', component: HistoricChartComponent }
  ]}
];

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

1 个答案:

答案 0 :(得分:1)

(代表作者提问回答)

问题在于:

this.router.navigate(['/simulation/distributed-chart/' + this.invested.risk]);

我应该添加"模拟"在路由器导航开始时,解决了!