Skip to content

Commit 70a4272

Browse files
arkisttimdorr
authored andcommitted
fix: Pass transition hook's arguments correctly (#4123)
1 parent 32728be commit 70a4272

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

modules/TransitionUtils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ export function runEnterHooks(routes, nextState, callback) {
8282
enterHooks.clear()
8383
const hooks = getEnterHooks(routes)
8484
return runTransitionHooks(hooks.length, (index, replace, next) => {
85-
const wrappedNext = () => {
85+
const wrappedNext = (...args) => {
8686
if (enterHooks.has(hooks[index])) {
87-
next()
87+
next(...args)
8888
enterHooks.remove(hooks[index])
8989
}
9090
}
@@ -106,9 +106,9 @@ export function runChangeHooks(routes, state, nextState, callback) {
106106
changeHooks.clear()
107107
const hooks = getChangeHooks(routes)
108108
return runTransitionHooks(hooks.length, (index, replace, next) => {
109-
const wrappedNext = () => {
109+
const wrappedNext = (...args) => {
110110
if (changeHooks.has(hooks[index])) {
111-
next()
111+
next(...args)
112112
changeHooks.remove(hooks[index])
113113
}
114114
}

modules/__tests__/transitionHooks-test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { routerShape } from '../PropTypes'
66
import execSteps from './execSteps'
77
import Router from '../Router'
88
import Route from '../Route'
9+
import match from '../match'
910

1011
describe('When a router enters a branch', function () {
1112
let
@@ -397,13 +398,17 @@ describe('Changing location', () => {
397398
cb()
398399
})
399400
}
401+
const onEnterError = (state, replace, cb) => {
402+
cb(new Error('transition error'))
403+
}
400404
const createRoutes = ({ enter, change }) => [
401405
<Route path="/" onChange={change ? onChange : noop} component={Text('Home')}>
402406
<Route path="child1" component={Text('Child1')} />
403407
<Route path="child2" component={Text('Child2')} />
404408
</Route>,
405409
<Route path="/foo" onEnter={enter ? onEnter : noop} component={Text('Foo')} />,
406-
<Route path="/bar" component={Text('Bar')} />
410+
<Route path="/bar" component={Text('Bar')} />,
411+
<Route path="/error" onEnter={enter ? onEnterError : noop} component={Text('Error')}/>
407412
]
408413

409414
beforeEach(() => {
@@ -443,4 +448,16 @@ describe('Changing location', () => {
443448
})
444449
})
445450
})
451+
452+
it('should pass error correctly', (done) => {
453+
const routes = createRoutes({ enter: true })
454+
455+
match({ routes, location: '/error' }, (error, redirectLocation, renderProps) => {
456+
expect(error).toExist()
457+
expect(error.message).toEqual('transition error')
458+
expect(redirectLocation).toNotExist()
459+
expect(renderProps).toNotExist()
460+
done()
461+
})
462+
})
446463
})

0 commit comments

Comments
 (0)