Angular 2 Routing run in new tab

前端 未结 5 1500
时光取名叫无心
时光取名叫无心 2020-11-29 06:49

I am working with a asp.net core application with angular2 and my routing is working fine.



        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 07:47

    Late to this one, but I just discovered an alternative way of doing it:

    On your template,

    Associates 
    

    And on your component.ts, you can use serializeUrl to convert the route into a string, which can be used with window.open()

    navigateAssociates() {
      const url = this.router.serializeUrl(
        this.router.createUrlTree(['/page1'])
      );
    
      window.open(url, '_blank');
    }
    

提交回复
热议问题