how to go to another page with a button click with ionic?

后端 未结 12 1957
粉色の甜心
粉色の甜心 2020-12-31 10:26

I have been trying to work with the code, I added the button but I don\'t know how to link it to another page when clicking on it.

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 10:47

    For Ionic 5 - below code is working for me, with Ionic 5 + Angular 9 combination,

    Step 1 - In html file, add the code to "define" the function,

    Go to Homepage
    

    Step 2 - In the constructor of your class, you can Inject the NavController - Injecting NavController will always get you an instance of the nearest NavController, regardless of whether it is a Tab or a Nav.

    constructor(public navCtrl: NavController) { }
    

    Step 3 - In TS file for your component, add the method that you are calling on click of ion-button,

    gotoHomePage() {
        this.navCtrl.navigateForward('home');
      }
    

    Here the 'home' is defined route in your app-routing.module.ts file, like below,

    { path: 'home', loadChildren: () => import('./home/home.module').then(m => m.HomePageModule) },
    

提交回复
热议问题