gpt4 book ai didi

angular - 在 Angular 路由中从堆栈中删除以前的页面

转载 作者:行者123 更新时间:2023-12-05 08:39:56 26 4
gpt4 key购买 nike

我是 Angular 的新手,我想尝试在其上构建我的应用程序。我只有一个普通的两页应用程序。我可以看到路由行为正常,但是我可以看到当我从键盘上按回键时,我回到了登录页面。

login -> homepageback button pressed homepage -> login

现在我想从堆栈中删除登录页面,所以当我们按下键盘返回时,它什么也不做。就像每次访问此类页面时从堆栈中删除上一页一样。我不希望我的用户在未注销的情况下返回到 login page

首页:

//going to the home page with this click on the button 
<button type="submit" class="btn btn-primary" (click)="submit()">Submit</button>

submit(){
(<any> window).location = '/home';
}

对于 logout 也是一样,我只是在做同样的事情:

注销:

<div class="logout-link col-4">
<a routerLink="/">Logout</a>
</div>

到目前为止我已经尝试过这样做:

//homepage logout button
[routerlink] = "['/', {clearhistory: true}]" //This disabled the route functioning at all, I could not go to home by tapping on the logout button.

//loginpage submit button
submit(){
this.route.navigate(['/home'], {clearhistory: true}) //did nothing I can again come back with the keyboard back
}

有什么办法可以达到我想要达到的效果。谢谢

最佳答案

您要查找的选项是 replaceUrl .这将替换历史记录中的状态,您将无法返回到之前的 URL。

或者,您也可以使用 skipLocationChange无需将状态插入历史即可导航。

this.route.navigate(['/home'], { replaceUrl: true });

关于angular - 在 Angular 路由中从堆栈中删除以前的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57915373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com