Angular2 RC1 child routes defined but not recognized

大城市里の小女人 提交于 2019-12-03 07:03:00
Vu Than

Note that the path can only be 'heroes'. if I change to [routerLink] and @Routes to '/heroes' it won't work. Can some help explain why?

Actually paths in child router can contain "/" as prefix but changing routerLink to "/heroes" made it not work because "/" prefix in navigation path will be resolved using root router and does not have "/heroes" path. "heroes" path worked because it will be resolved using current router and you defined that path in current child router.

this._router.navigate(['hero/'+hero._id]);

Calling "navigate" without a segment will be resolved using root router. It means you want to do absolute navigation. Obviously this will not work.

this._router.navigate(['hero/'+hero._id],this.currSegment);

This also did not work because you are at HeroesComponent and "heroes" segment, there is no router configuration in the component. The correct call should be:

this._router.navigate(['../hero', {_id: hero._id}], this.currSegment);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!