Skip to content

Commit 7adf8b8

Browse files
tpteemjackson
authored andcommitted
Fix the back button in Chrome iOS (#383)
* Fix the back button in Chrome iOS * Remove extraneous date in CHANGES.md
1 parent e443454 commit 7adf8b8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## HEAD
2+
3+
- Fix the back button on Chrome iOS
4+
15
## [v4.4.0]
26
> Nov 1, 2016
37

modules/DOMUtils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ export const supportsPopStateOnHashChange = () =>
4343
*/
4444
export const supportsGoWithoutReloadUsingHash = () =>
4545
window.navigator.userAgent.indexOf('Firefox') === -1
46+
47+
/**
48+
* Returns true if a given popstate event is an extraneous WebKit event.
49+
* Accounts for the fact that Chrome on iOS fires real popstate events
50+
* containing undefined state when pressing the back button.
51+
*/
52+
export const isExtraneousPopstateEvent = event =>
53+
event.state === undefined &&
54+
navigator.userAgent.indexOf('CriOS') === -1

modules/createBrowserHistory.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
removeEventListener,
1010
getConfirmation,
1111
supportsHistory,
12-
supportsPopStateOnHashChange
12+
supportsPopStateOnHashChange,
13+
isExtraneousPopstateEvent
1314
} from './DOMUtils'
1415

1516
const PopStateEvent = 'popstate'
@@ -79,8 +80,9 @@ const createBrowserHistory = (props = {}) => {
7980
}
8081

8182
const handlePopState = (event) => {
82-
if (event.state === undefined)
83-
return // Ignore extraneous popstate events in WebKit.
83+
// Ignore extraneous popstate events in WebKit.
84+
if (isExtraneousPopstateEvent(event))
85+
return
8486

8587
handlePop(getDOMLocation(event.state))
8688
}

0 commit comments

Comments
 (0)