0

When I execute this code to redirectTo other component

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

I have this issue in console:

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

app-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 { }

simulation-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 { }
5
  • this.invested.risk is not defined. You should add crucial content to your question. Commented May 2, 2018 at 7:43
  • 2
    with your config it sould be this.router.navigate(['/simulation/distributed-chart/' + this.invested.risk]); if I am not mistaken Commented May 2, 2018 at 7:53
  • try to write the proper url manually in the browser until you find it and then you will easily spot the mistake ;) Commented May 2, 2018 at 7:57
  • The problem was here => this.router.navigate(['/simulation/distributed-chart/' + this.invested.risk]); I should add "simulation" at start of the router navigation, SOLVED! Commented May 2, 2018 at 8:05
  • Pro-tip: we prefer not to use the title to mark questions as solved here. The best way to do that is via an answer. I will post that for you, but if you would like to post it under your own name, ping me and I will delete my copy. Commented May 2, 2018 at 21:38

1 Answer 1

1

(Posted answer on behalf of the question author).

The problem was here:

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

I should add "simulation" at start of the router navigation, solved!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.