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

查看:1506
本文介绍了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的路由有一种内置的方式可以跳过向状态添加状态。我们实际上发现它通过编辑器的intellisense中的随机属性进行检查。

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});

to:

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

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

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