Ionic 4 Angular路由器导航并清除上一页的堆栈/历史记录 [英] Ionic 4 Angular router navigate and clear stack/history of previous page

查看:645
本文介绍了Ionic 4 Angular路由器导航并清除上一页的堆栈/历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ionic 4和Angular路由器开发一个应用程序.我想导航到另一个页面并清除页面堆栈.在Android本机中,是这样的:

I'm developing an app using Ionic 4 with Angular router. I would like to navigate to another page and clear the page stack. In Android native, it's something like this:

Intent intent = new Intent(NewActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

到目前为止,我可以使用Ionic NavController进行操作,但在Ionic 4中已弃用.我了解了使用routerLink的按钮,但如果我没记错的话,通过使用该应用程序可以立即导航到另一页.在导航到另一页之前,我需要执行一些逻辑.

From what I've read so far, it is possible using Ionic NavController but it is deprecating in Ionic 4. I learnt about buttons with routerLink but if I'm not mistaken, by using that the app will immediately navigate to the other page. I need to execute some logic before navigating to another page .

例如:登录页面.成功登录后,用户将无法返回登录页面.另外,通过单击登录"按钮,它应该调用一个函数来处理登录并决定导航/不导航到另一个页面.

For example: Login page. After successful login, the user shouldn't be able to go back to the login page. Also, by clicking the 'login' button, it should call a function to process the login and decide to navigate/not navigate to another page.

我是否可以通过Angular路由器实现这一目标,还是需要依赖于弃用的Ionic NavController?

Is there any way that I can achieve this with Angular router or do I need to rely on the deprecating Ionic NavController?

推荐答案

this.router.navigateByUrl('/login', { skipLocationChange: true });

导航时不会将新状态推入历史记录.

Navigates without pushing a new state into history.

https://angular.io/api/router/NavigationExtras

这篇关于Ionic 4 Angular路由器导航并清除上一页的堆栈/历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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