I was upgrading my angular apps which run inside the Share Point office adds in. Currently angular app is using version 14, after I upgrade to angular 15 it works fine. But as soon as I upgrade to 16, I get below error.
TypeError: this._history.replaceState is not a function
This happens when calling
this.router.navigate(['/path_to_component']);
I found a fix on this SO post. Office.js nullifies browser history functions breaking history usage
<script type="text/javascript">
// Office js deletes window.history.pushState and window.history.replaceState. Cache them and restore them
window._historyCache = {
replaceState: window.history.replaceState,
pushState: window.history.pushState
};
</script>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script type="text/javascript">
// Office js deletes window.history.pushState and window.history.replaceState. Restore them
window.history.replaceState = window._historyCache.replaceState;
window.history.pushState = window._historyCache.pushState;
</script>
I am not sure how this is breaking only after upgrade to Angular 16 though its relate to office.js
I am using the same version of office.js.
I have already use hash location strategy. Could any one help me to understand this.