Skip to content

Commit fbcbd94

Browse files
committed
Include props and params on router in match()
1 parent 99e686c commit fbcbd94

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

modules/__tests__/serverRendering-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ describe('server rendering', function () {
152152
})
153153
})
154154

155+
it('includes params and location in the props', function (done) {
156+
match({ routes, location: '/dashboard' }, function (error, redirectLocation, renderProps) {
157+
expect(renderProps.params).toEqual({})
158+
expect(renderProps.router.params).toEqual({})
159+
160+
expect(renderProps.location.pathname).toEqual('/dashboard')
161+
expect(renderProps.router.location.pathname).toEqual('/dashboard')
162+
done()
163+
})
164+
})
165+
155166
it('accepts a basename option', function (done) {
156167
match({ routes, location: '/dashboard', basename: '/nasebame' }, function (error, redirectLocation, renderProps) {
157168
const string = renderToString(

modules/match.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,24 @@ function match({ history, routes, location, ...options }, callback) {
3939
})
4040
}
4141

42-
const router = createRouterObject(history, transitionManager)
43-
4442
transitionManager.match(location, function (error, redirectLocation, nextState) {
45-
callback(
46-
error,
47-
redirectLocation,
48-
nextState && {
43+
let renderProps
44+
45+
if (nextState) {
46+
const router = {
47+
...createRouterObject(history, transitionManager),
48+
location: nextState.location,
49+
params: nextState.params
50+
}
51+
52+
renderProps = {
4953
...nextState,
5054
router,
5155
matchContext: { transitionManager, router }
5256
}
53-
)
57+
}
58+
59+
callback(error, redirectLocation, renderProps)
5460

5561
// Defer removing the listener to here to prevent DOM histories from having
5662
// to unwind DOM event listeners unnecessarily, in case callback renders a

0 commit comments

Comments
 (0)