路由器链接数组并使用router.navigateURL单击事件

时间:2018-06-06 11:56:22

标签: angular angular-router

HTML

<li>
    <a id="appButton"
      class="toolbar left-nav-link"
      [routerLinkActive]="['toolbar--active']"
      [routerLink]="['/app']"
      (click)="goTo('/app')">
      <i class="icon-app" aria-hidden="true"></i>
      <span class="left-nav-sidebar__text">app</span>
    </a>
</li>

TS

goTo(root: string): void {
    const lastUrl: string = this.sessionStorageService.fetch(root) || root;
    this.router.navigateByUrl(lastUrl);
}

我正在为'/app'设置儿童路线。我需要用户[routerLink]才能激活[routerLinkActive]

点击appButton后,重定向到goTo - &gt;最后URL

此解决方案按预期工作。关注绩效

router.events.subscribe(event => {
      console.log(event);
});

控制台日志

NavigationStart {id: 6, url: "/app", navigationTrigger: "imperative", restoredState: null} 
NavigationCancel {id: 6, url: "/app", reason: "Navigation ID 6 is not equal to the current navigation id 7"} 
NavigationStart {id: 7, url: "/app/5aa584d4-df46-4ea8-8ba8-1866bf94b622", navigationTrigger: "imperative", restoredState: null} 
RoutesRecognized {id: 7, url: "/app/5aa584d4-df46-4ea8-8ba8-1866bf94b622", urlAfterRedirects: "/app/5aa584d4-df46-4ea8-8ba8-1866bf94b622", state: RouterStateSnapshot}

问题:

  

由于此启动路线'/ app'将具有任何性能或   记忆问题?   如果是这样,我们还有其他更清洁的方法吗?

0 个答案:

没有答案