简体   繁体   English

单击ionic中的按钮时如何导航到新屏幕

[英]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 ? 任何人都可以帮助我,如何通过单击ionic中的按钮来导航到新屏幕?

You don't use anchor tags like a normal HTML in ionic. 您不会在ionic中使用像普通HTML一样的锚标记。

you should be using 'navController' to navigate between views. 您应该使用“ navController”在视图之间导航。

the Ionic documentation for NavController is the great place to read about this NavControllerIonic文档是了解此内容的好地方

You need to define the routes in your ngModules like this: 您需要像这样在ngModules中定义路由:

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). 这将调用将在HTML中包含模板的组件(您不调用html文件)。

Then you can use something like this in the template: 然后,您可以在模板中使用以下内容:

[routerLink]="['tranaddnew']"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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