Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 608
Matias graña Avatar asked Apr 08 '17 01:04

Matias graña


2 Answers

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.

like image 144
Aref Zamani Avatar answered Oct 17 '22 21:10

Aref Zamani


I faced the same issue. The basic reason was, It wasn't finding the LINK (url) for the the item. i.e.

BEFORE

 {     e2eId: '1',     title: 'myTitle',     link: null,     icon: 'icon',     isActive: false,    } 

AFTER

{     e2eId: '1',     title: 'myTitle',     link: '/somelinehere',     icon: 'icon',     isActive: false,    } 

This issue may also arise due to Null value of id or something else with null value as well.

like image 30
Analyst Avatar answered Oct 17 '22 21:10

Analyst