Angular2 Routing. The requested path contains undefined segment at index 1

Matias graña picture Matias graña · Apr 8, 2017 · Viewed 30.8k times · Source

I have a issue with routing in Angular 2. I call router.navigate from an action into a datatable. The rare is that sometimes when i click the button that calls this line its works fine and sometimes it doesnt.

this.router.navigate(['edit', id], {relativeTo: this.activatedRoute});

The error that shows the inspector element is:

The requested path contains undefined segment at index 1

Im using Angular2, DataTables, and Webpack

Answer

Aref Zamani picture Aref Zamani · Jan 8, 2018

Probably your id that pass into in navigate is undefined or null.console your id and fix and then pass into in navigate .i had same issue and fixed it.