Skip to content

Commit

Permalink
fix: 🐛 bind history to window (#428)
Browse files Browse the repository at this point in the history
* fix: 🐛 bind history to window

✅ Closes: #426
  • Loading branch information
maoxiaoke authored Oct 20, 2021
1 parent df759e1 commit 78f7507
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/icestark-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/icestark-app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/icestark-app/src/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}}
Expand Down
7 changes: 5 additions & 2 deletions src/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ const AppLink: React.SFC<AppLinkProps> = (props: AppLinkProps) => {
<a
{...rest}
href={linkTo}
onClick={e => {
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);
}}
Expand Down

0 comments on commit 78f7507

Please sign in to comment.