简体   繁体   中英

Multiple binding of child routes with angular new router

I'm working on a project with the new angular router and have run into an issue where my child routes get bound multiple times. Here is a quick example showing the issue:

http://plnkr.co/edit/pZ25uCxHu5O5BcBcDbrO?p=preview

Basic navigation controls and viewport in the index.html

<md-continer layout="row">
  <a ng-link="one()">One</a> 
  &nbsp; | &nbsp;
  <a ng-link="two()">Two</a>
</md-continer>
<div ng-viewport></div>

Once I add this viewport to page two, the code in both controllers starts repeating itself.

<div ng-viewport></div>

Each component controller has a console.log when it is loaded. If you watch your console when switching between components and one of them contains its own ng-viewport, you will start to get duplicate logs from the controller. When I remove the component ng-viewport, the error stops. Does anybody have any experience with this?

I wonder if you might have hit this issue; https://github.com/angular/router/issues/204 which is currently open against the new router, and references a couple of similar issues that may be worth you checking as well. If not, you could log a new issue with your example, it looks like the team are active at looking at issues logged on github

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM