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

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.

主站蜘蛛池模板: 泉州市| 财经| 博野县| 鄂托克前旗| 钟祥市| 封丘县| 汉沽区| 三台县| 余姚市| 华亭县| 株洲市| 通榆县| 丘北县| 武宣县| 龙游县| 芒康县| 鸡东县| 忻城县| 泸溪县| 曲松县| 舟曲县| 诸暨市| 大竹县| 贺兰县| 出国| 长海县| 将乐县| 建阳市| 平度市| 平和县| 徐汇区| 四会市| 江永县| 巩义市| 岱山县| 佛教| 沅陵县| 临湘市| 富裕县| 辽阳县| 娄烦县|