Angular 2: Prevent router from adding to history

别说谁变了你拦得住时间么 提交于 2019-12-03 12:32:38

问题


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.

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.

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


回答1:


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



来源:https://stackoverflow.com/questions/42028397/angular-2-prevent-router-from-adding-to-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!