Angular2 RC1 child routes defined but not recognized

后端 未结 1 1053
清酒与你
清酒与你 2021-02-09 02:50

What used to work for beta /... is no longer working. With the new new RC1 router, how do I do the child routing?

Folder structure

app
  |--home/
  |             


        
相关标签:
1条回答
  • 2021-02-09 03:29

    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);
    
    0 讨论(0)
提交回复
热议问题