Skip to content

Commit

Permalink
Merge pull request #167 from taion/hash-replace
Browse files Browse the repository at this point in the history
Consider the full path in changing PUSH to REPLACE
  • Loading branch information
taion committed Dec 1, 2015
2 parents ce96689 + 32a3978 commit 331ee28
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
## [HEAD]

#### Bug fixes
- Disable browser history on Chrome iOS ([#146])
- Do not convert same-path PUSH to REPLACE if the hash has changed ([#167])

#### Other
- Add ES2015 module build ([#152])

[HEAD]: https://github.com/rackt/history/compare/latest...HEAD
[#146]: https://github.com/rackt/history/pull/146
[#152]: https://github.com/rackt/history/pull/152
[#167]: https://github.com/rackt/history/pull/167

## [v1.13.1]
> Nov 13, 2015
Expand Down
23 changes: 23 additions & 0 deletions modules/__tests__/describeHashSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ function describeHashSupport(createHistory) {

unlisten = history.listen(execSteps(steps, done))
})

it('does not convert PUSH to REPLACE if path does not change', function (done) {
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.hash).toEqual('')
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)

history.pushState(null, '/#the-hash')
},
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.hash).toEqual('#the-hash')
expect(location.state).toEqual(null)
expect(location.action).toEqual(PUSH)
}
]

unlisten = history.listen(execSteps(steps, done))
})
})
}

Expand Down
7 changes: 3 additions & 4 deletions modules/createHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ function createHistory(options={}) {
if (ok) {
// treat PUSH to current path like REPLACE to be consistent with browsers
if (nextLocation.action === PUSH) {
let { pathname, search } = getCurrentLocation()
let currentPath = pathname + search
let path = nextLocation.pathname + nextLocation.search
const prevPath = createPath(location)
const nextPath = createPath(nextLocation)

if (currentPath === path)
if (nextPath === prevPath)
nextLocation.action = REPLACE
}

Expand Down

0 comments on commit 331ee28

Please sign in to comment.