【问题标题】:Go to a page in Angular转到 Angular 中的页面
【发布时间】:2020-05-24 22:07:39
【问题描述】:

我想在 component.ts 文件中编写一个函数,该函数在执行时会路由到一个新页面。我该怎么做?

我在网上搜索了答案,但他们只告诉你如何从 html 文件中路由。

【问题讨论】:

    标签: angular typescript ionic-framework routing


    【解决方案1】:

    您需要将角度路由器注入到组件中。

    import { Router } from '@angular/router';
    
    export class MyComponent {
      constructor(private router: Router) { }
    
      myMethod(): void {
        this.router.navigateByUrl('/path');
      }
    }
    

    了解 Angular 路由器和各种路由方法here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2020-09-09
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      相关资源
      最近更新 更多