- 97
- 0
ionic做的页面在浏览器访问时点击返回按钮直接就退出这个页面了,如何修改成返回上一个页面
- 共 0 条
- 全部回答
-
残阳秋鹤影 普通会员 1楼
在ionic3中,你可以在组件或服务中使用返回按钮返回上一页,以下是一个简单的示例:
- 在
App组件中,设置返回按钮的样式和事件监听器:
```typescript import { Component } from '@angular/core'; import { IonBottomSheet, IonBottomSheetRef } from '@ionic/material/bottom-sheet'; import { Router } from '@angular/router';
@Component({ selector: 'app-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { bottomSheetRef: IonBottomSheetRef;
constructor(private router: Router) {}
goToPreviousPage() { this.bottomSheetRef?.close(); this.router.navigate(['/prev']); } } ```
- 在
app.component.html文件中,添加返回按钮:
html <ion-bottom-sheet #bottomSheetRef (ionBottomSheetClosing)="goToPreviousPage()"> <ion-button (click)="goToPreviousPage()">Previous</ion-button> </ion-bottom-sheet>- 在
app.component.ts文件中,处理返回按钮的点击事件:
```typescript import { Component, OnInit } from '@angular/core'; import { IonBottomSheet } from '@ionic/material/bottom-sheet'; import { Router } from '@angular/router';
@Component({ selector: 'app-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { bottomSheetRef: IonBottomSheetRef;
constructor(private router: Router) {}
ngOnInit() { this.bottomSheetRef = this.createBottomSheetRef(); }
createBottomSheetRef() { return new IonBottomSheet({ heading: 'Previous Page', icon: 'ios-arrow-back', cancelText: 'Cancel', confirmText: 'Previous', headerText: 'Go to Previous Page', footerText: 'Done' }); }
goToPreviousPage() { this.bottomSheetRef?.close(); this.router.navigate(['/prev']); } } ```
在这个示例中,我们首先在
app.component.ts中创建了一个IonBottomSheetRef对象,然后在ngOnInit方法中初始化它。然后,我们定义了一个名为createBottomSheetRef的方法,该方法返回一个新的IonBottomSheet对象,该对象包含了返回按钮的样式、图标和文本。在
app.component.html文件中,我们添加了一个返回按钮,并在ionBottomSheetClosing事件处理函数中调用了createBottomSheetRef方法创建一个新的IonBottomSheet对象,然后关闭它并调用goToPreviousPage方法,以返回上一页。注意:在实际使用中,你可能需要根据你的需求和项目的具体配置来调整这个示例,例如更改返回按钮的样式、图标、文本等,以及在
createBottomSheetRef方法中添加更多的自定义属性和事件监听器。 - 在
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
