Angular 2:防止路由器添加到历史记录 [英] Angular 2: Prevent router from adding to history

查看:50
本文介绍了Angular 2:防止路由器添加到历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个客户端,在我们的应用中使用 iFraming 到他们的网站.他们不希望我们应用程序中的路由器导航影响他们自己网站的后退按钮导航.

We have a client that is iFraming in our app to their website. They don't want the router navigation within our app to affect the back button navigation for their own site.

我们尝试了几种方法,包括使用 post 消息来尝试让 iFrame 在触发 history.back() 时与父窗口进行通信.

We've tried a couple methods including using post messages to try and have the iFrame communicate with the parent window whenever a history.back() is triggered.

我的问题是,在使用 Angular 2 的路由器时,是否有任何简单的方法可以不影响浏览器的历史记录.据我所知,我在 Angular 2 的高级路由器文档中找不到任何内容:https://angular.io/docs/ts/latest/guide/router.html

My question is if there is any easy way to not affect the browser's history when using Angular 2's router. As far as I know, I couldn't find anything within Angular 2's advanced router documentation: https://angular.io/docs/ts/latest/guide/router.html

推荐答案

事实证明,Angular 2 的路由有一种内置方式可以跳过向历史添加状态.我们实际上发现它通过编辑器智能感知中的随机属性进行检查.

It turns out there is a built-in way for Angular 2's routing to skip adding a state to the history. We actually found it checking through random properties inside the intellisense of the editor.

我们的路由代码必须来自:

Our routing code just had to go from:

this.router.navigate([`/myPage/${this.Id}`], { relativeTo: this.route });

到:

this.router.navigate([`/myPage/${this.Id}`], { relativeTo: this.route, skipLocationChange: true });

这篇关于Angular 2:防止路由器添加到历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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