From 78f750723fcdfc1ef957a589c6f2d99c5070aa1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=A3=E5=90=92?= Date: Wed, 20 Oct 2021 14:12:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20bind=20history=20to=20win?= =?UTF-8?q?dow=20(#428)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 bind history to window ✅ Closes: #426 --- packages/icestark-app/CHANGELOG.md | 4 ++++ packages/icestark-app/package.json | 2 +- packages/icestark-app/src/AppLink.tsx | 5 ++++- src/AppLink.tsx | 7 +++++-- 4 files changed, 14 insertions(+), 4 deletions(-) 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); }}