ionic3 刷新页面之后,回退按钮消失

参考 How can i reload the current page in Ionic 3 when i refresh the browser? 的回复,


我的代码:

@IonicPage(
  {
    defaultHistory: ['MainPage'] //设置上个页面的名称,defaultHistory 是在这个页面没有历史记录的情况下(比如直接刷新当前页面)设置一个默认的历史记录,告知页面,是从哪个页面跳转到当前页面的一个历史记录,会显示一个返回到指定页面的 返回按钮
  }
)
@Component({
  selector: 'page-test',
  templateUrl: 'test.html',
})
export class TestPage {}

文档 IonicPage 中 提到 Default History ,默认的历史记录

The default history of any page can be set in the defaultHistory property. This history will only be used if the history doesn't already exist, meaning if you navigate to the page the history will be the pages that were navigated from.
The defaultHistory property takes an array of strings. For example, setting the history of the detail page to the list page where the name is list:

一些页面的默认的历史记录记录在 defaultHistory 属性中。这个属性只使用在历史记录不存在的情况下,管理你的这个页面是从哪个页面跳过来的历史记录。

这个 defaultHistory 属性是一个字符串数组。比如: 设置从页面名为 list 页面跳转到详情页面的历史记录。

@IonicPage({
  name: 'detail-page', //页面名
  segment: 'detail/:id',
  defaultHistory: ['list']
})

In this example, if the app is launched at http://localhost:8101/#/detail/my-detail the displayed page will be the 'detail-page' with an id of my-detail and it will show a back button that goes back to the 'list' page.
An example of an application with a set history stack is the Instagram application. Opening a link to an image on Instagram will show the details for that image with a back button to the user's profile page. There is no "right" way of setting the history for a page, it is up to the application.

在这个例子,如果应用是在 http://localhost:8101/#/detail/my-detail 发起页面访问,这个详情页面的页面名为 'detail-page'和将会显示一个 跳回到 list(页面名)页面 的返回按钮。

另外一个例子是Instagram应用 设置历史记录存储栈.在Instagram 应用中打开一个图片链接,将会显示这个图片详情和一个返回按钮回到用户个人资料页面。这个没有“可能”的方式设置这个页面的历史记录,这个属性就可以给应用处理这个问题.

posted @ 2022-07-27 23:55  五毛钱的饼  阅读(170)  评论(0编辑  收藏  举报