diff --git a/packages/icestark-app/CHANGELOG.md b/packages/icestark-app/CHANGELOG.md index 890dd5be..12ce1bbc 100644 --- a/packages/icestark-app/CHANGELOG.md +++ b/packages/icestark-app/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.4.2 + +- [fix] Bind history to window when using `AppLink`. ([#428](https://github.com/ice-lab/icestark/pull/428)) + ## 1.4.1 - [feat] correct types of `setLibraryName`. ([#287](https://github.com/ice-lab/icestark/issues/287)) diff --git a/packages/icestark-app/package.json b/packages/icestark-app/package.json index 307f0869..3ce29234 100644 --- a/packages/icestark-app/package.json +++ b/packages/icestark-app/package.json @@ -1,6 +1,6 @@ { "name": "@ice/stark-app", - "version": "1.4.1", + "version": "1.4.2", "description": "icestark-app is a JavaScript library for icestark, used by sub-application.", "scripts": { "build": "rm -rf lib && tsc", diff --git a/packages/icestark-app/src/AppLink.tsx b/packages/icestark-app/src/AppLink.tsx index 67f44c8f..0f6924e5 100644 --- a/packages/icestark-app/src/AppLink.tsx +++ b/packages/icestark-app/src/AppLink.tsx @@ -23,7 +23,10 @@ const AppLink = (props: AppLinkProps) => { return false; } - const changeState = window.history[replace ? 'replaceState' : 'pushState']; + /* + * Bind `replaceState` and `pushState` to window to avoid illegal invocation error + */ + const changeState = window.history[replace ? 'replaceState' : 'pushState'].bind(window); changeState({}, null, linkTo); }} diff --git a/src/AppLink.tsx b/src/AppLink.tsx index 2c621096..5d4c37ce 100644 --- a/src/AppLink.tsx +++ b/src/AppLink.tsx @@ -15,13 +15,16 @@ const AppLink: React.SFC = (props: AppLinkProps) => { { + onClick={(e) => { e.preventDefault(); if (message && window.confirm(message) === false) { return false; } - const changeState = window.history[replace ? 'replaceState' : 'pushState']; + /* + * Bind `replaceState` and `pushState` to window to avoid illegal invocation error + */ + const changeState = window.history[replace ? 'replaceState' : 'pushState'].bind(window); changeState({}, null, linkTo); }}