简体   繁体   中英

how to navigate to new screen on click of a button in ionic

This my code for calling a page on click of a button

<a href="tranaddnew.html" class="btn btn-success">Add a new</a>

I am getting the following output.

Cannot GET /tranaddnew.html

Can anyone help me how to navigate to new screen on click of a button in ionic ?

You don't use anchor tags like a normal HTML in ionic.

you should be using 'navController' to navigate between views.

the Ionic documentation for NavController is the great place to read about this

You need to define the routes in your ngModules like this:

const routes: Routes = [
  {path: 'tranaddnew', component: tranaddnewPage},
];

@NgModule({
  declarations: [
   tranaddnewPage,
  ],
  imports: [
    RouterModule.forChild(routes),
  ]
})
export class HomeModule {
}

This will call a component that will be including a template in HTML (you don't call an html file).

Then you can use something like this in the template:

[routerLink]="['tranaddnew']"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM