转到Angular页面

问题描述 投票:0回答:1

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

我已经在线搜索了答案,但它们只告诉您如何从html文件进行路由。

angular typescript ionic-framework routing
1个回答
0
投票

您需要将角铣刀注入组件中。

import { Router } from '@angular/router';

export class MyComponent {
  constructor(private router: Router) { }

  myMethod(): void {
    this.router.navigateByUrl('/path');
  }
}

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

© www.soinside.com 2019 - 2024. All rights reserved.