Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider the full path in changing PUSH to REPLACE #167

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not 100% correct, since it doesn't e.g. account for basename when using browser history. In practice that's not an issue, though, since basename doesn't change.

This should be the "final" createPath, but I can't access that here.

const nextPath = createPath(nextLocation)

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

Expand Down