@Everton Costa 的答案是答案的一部分,但会在其中进行一些编辑。
const routes: Routes = [
{
path: '',
redirectTo: '/login',
pathMatch: 'full'
},
{
path: 'home',
loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
},
{
path: 'login',
loadChildren: () => import('./login/login.module').then(m => m.LoginModule)
}
];
为了执行导航,你可以在按钮本身上放置类似 routerLink 的属性
<ion-button routerLink="/home"></ion-button>
或者我们可以通过在 login.component.ts 文件中添加以下代码来访问它:
首先你在这个页面的顶部添加这一行:
import { Router } from '@angular/router';
并在构造函数中添加:
constructor(private router: Router){}
navigateToPage(route: string) {
this.router.navigate([route]);
}
在 html 中:
<ion-button (click)="navigateToPage('/home')"></ion-button>