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

痴心易碎 提交于 2021-02-06 14:42:10

问题


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


回答1:


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.




回答2:


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.




回答3:


I had the same issue. When I inspected the values passed to the navigate function, I found that my url was undefined. Actually, the main problem was that I tried to navigate before the data was ready. You have to check first if your data is ready to be passed. Like waiting for an event or be subscribed to another callback.



来源:https://stackoverflow.com/questions/43289366/angular2-routing-the-requested-path-contains-undefined-segment-at-index-1

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