Skip to content

Commit

Permalink
Fix hash support
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Oct 6, 2015
1 parent 795c75f commit 7012f9b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/__tests__/BrowserHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
import describePushState from './describePushState'
import describeReplaceState from './describeReplaceState'
import describeHashSupport from './describeHashSupport'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
import describeGo from './describeGo'
Expand All @@ -19,6 +20,7 @@ describe('browser history', function () {
describeTransitions(createBrowserHistory)
describePushState(createBrowserHistory)
describeReplaceState(createBrowserHistory)
describeHashSupport(createBrowserHistory)
describeBasename(createBrowserHistory)
describeQueries(createBrowserHistory)
describeGo(createBrowserHistory)
Expand All @@ -28,6 +30,7 @@ describe('browser history', function () {
describeTransitions(createBrowserHistory)
describePushState(createBrowserHistory)
describeReplaceState(createBrowserHistory)
describeHashSupport(createBrowserHistory)
describeBasename(createBrowserHistory)
describeQueries(createBrowserHistory)
describeGo(createBrowserHistory)
Expand Down
4 changes: 2 additions & 2 deletions modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function describeStatePersistence(createHistory) {
})

it('forgets state across transitions', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand Down Expand Up @@ -74,7 +74,7 @@ function describeStatePersistence(createHistory) {
})

it('remembers state across transitions', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand Down
43 changes: 43 additions & 0 deletions modules/__tests__/describeHashSupport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*eslint-env mocha */
import expect from 'expect'
import { PUSH, POP } from '../Actions'
import execSteps from './execSteps'

function describeHashSupport(createHistory) {
describe('when a URL with a hash is pushed', function () {
let history, unlisten
beforeEach(function () {
history = createHistory()
})

afterEach(function () {
if (unlisten)
unlisten()
})

it('preserves the hash', 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({ the: 'state' }, '/home?the=query#the-hash')
},
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('?the=query')
expect(location.hash).toEqual('#the-hash')
expect(location.state).toEqual({ the: 'state' })
expect(location.action).toEqual(PUSH)
}
]

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

export default describeHashSupport
4 changes: 2 additions & 2 deletions modules/createBrowserHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ function createBrowserHistory(options) {
}

function finishTransition(location) {
let { basename, pathname, search, state, action, key } = location
let { basename, pathname, search, hash, state, action, key } = location

if (action === POP)
return // Nothing to do.

saveState(key, state)

let path = (basename || '') + pathname + search
let path = (basename || '') + pathname + search + hash
let historyState = {
key
}
Expand Down

0 comments on commit 7012f9b

Please sign in to comment.