官术网_书友最值得收藏!

Navigation

So at this point the router has created a router state and instantiated the components. Next, we need to be able to navigate from this router state to another one. There are two ways to accomplish this: imperatively, by calling router.navigate, or declaratively, by using the RouterLink directive.

Imperative navigation

To navigate imperatively, inject the Router service and call navigate:

@Component({...})
class MessageCmp {
  public id: string;
  constructor(private route: ActivatedRoute, private router: Router) {
    route.params.subscribe(_ => this.id = _.id);
  }

  openPopup(e) {
    this.router.navigate([{outlets: {popup: ['message',          
    this.id]}}]).then(_ => {
      // navigation is done
    });
  }
}

RouterLink

Another way to navigate around is by using the RouterLink directive:

@Component({
  template: `
    <a [routerLink]="['/', {outlets: {popup: ['message',        
    this.id]}}]">Edit</a>
  `
})
class MessageCmp {
  public id: string;
  constructor(private route: ActivatedRoute) {
    route.params.subscribe(_ => this.id = _.id);
  }
}

This directive will also update the href attribute when applied to an <a> link element, so it is SEO friendly and the right-click open-in-new-browser-tab behavior we expect from regular links will work.

主站蜘蛛池模板: 嵊泗县| 衡东县| 全椒县| 福贡县| 贞丰县| 宿迁市| 外汇| 灵武市| 玉溪市| 克什克腾旗| 亳州市| 平乡县| 贺州市| 时尚| 高要市| 新巴尔虎左旗| 永川市| 莒南县| 阿勒泰市| 宁河县| 涟源市| 介休市| 昭觉县| 安新县| 南康市| 吉隆县| 崇礼县| 晋中市| 安龙县| 内江市| 密云县| 泊头市| 清徐县| 兰溪市| 汝州市| 贵港市| 荣昌县| 邓州市| 怀化市| 丰县| 革吉县|