Ionic 4 Angular Back Button到上一页而不是root? [英] Ionic 4 Angular Back Button to previous page instead of root?

查看:152
本文介绍了Ionic 4 Angular Back Button到上一页而不是root?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带2个标签和1个详细信息页面的Ionic 4应用程序。
我在这里面临的问题是,如果我从Tab2进入详细信息页面,然后使用 ion-back-button 回到那里,它将始终将我重定向到Tab1

I have a little Ionic 4 App with 2 Tabs and 1 Detail Page. The Problem I'm facing here is that if I go from Tab2 into Detail Page and from there with ion-back-button back it always redirect me to Tab1 instead of Tab2 where I was before.

这里是我的示例:

Tab2 Html:
这里我有一个带有点击事件的简单离子项目:

Tab2 Html: Here I have a simple ion-item with a click event:

        <ion-item class="chat-item" (click)='openChat()' >

调用openChat函数,其工作方式如下:

It calls the openChat funtion which works like this:

          openChat() {
            this.router.navigateByUrl('/chatdetail/:uid');
          }

现在,它会打开我的Chatdetail页面,在该页面中我放置了一个后退按钮以进行导航像这样

Now it opens my Chatdetail Page in which I have placed a Back Button to navigate back like this:

    <ion-header>
      <ion-toolbar>
          <ion-buttons slot="start">
              <ion-back-button></ion-back-button>
           </ion-buttons>
        <ion-title>chatdetail</ion-title>
      </ion-toolbar>
    </ion-header>

但是当我单击此按钮时,它不仅像在Ionic3中那样弹出页面而是将我定向到我的应用程序的根页面,即Tab1。

But when I click this Button it doesn't just "pop" the page like it was in Ionic3 instead it directs me to the root page of my App which is Tab1.

是否有任何方法可以覆盖该后退事件以转到我之前所在的页面?

Is there any way of overwriting that back event to go to the page I was before?

推荐答案

更新:

离子团队已在Ver上修复了此问题: 4.3.0

Ionic team has fixed this on Ver: 4.3.0

您需要像这样使用 defaultHref = / Tab2

  <ion-back-button defaultHref="/Tab2"></ion-back-button>




在没有历史记录的情况下默认返回的URL。

The url to navigate back to by default when there is no history.

https://ionicframework.com/docs/api/后退按钮

如何转到上一页?

import {Location} from @ angular / common;

构造函数(私有位置:位置){}

myBackButton(){
  this.location.back();
}

这篇关于Ionic 4 Angular Back Button到上一页而不是root?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆