Skip to content

Commit a76efdd

Browse files
committed
Move handling of params and location into createRouterObject
1 parent fbcbd94 commit a76efdd

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

modules/Router.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,7 @@ const Router = React.createClass({
6262
}
6363

6464
const { history } = this.props
65-
const router = createRouterObject(history, this.transitionManager)
66-
67-
return {
68-
...router,
69-
location: state.location,
70-
params: state.params
71-
}
65+
return createRouterObject(history, this.transitionManager, state)
7266
},
7367

7468
createTransitionManager() {

modules/RouterUtils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
export function createRouterObject(history, transitionManager) {
1+
export function createRouterObject(history, transitionManager, state) {
22
return {
33
...history,
44
setRouteLeaveHook: transitionManager.listenBeforeLeavingRoute,
5-
isActive: transitionManager.isActive
5+
isActive: transitionManager.isActive,
6+
location: state.location,
7+
params: state.params
68
}
79
}

modules/__tests__/RouterContext-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('RouterContext', () => {
3131
isActive: expect.createSpy().andReturn(isActiveSentinel)
3232
}
3333

34-
router = createRouterObject(history, transitionManager)
34+
router = createRouterObject(history, transitionManager, {})
3535

3636
class Component extends React.Component {
3737
constructor(props, ctx) {

modules/match.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ function match({ history, routes, location, ...options }, callback) {
4343
let renderProps
4444

4545
if (nextState) {
46-
const router = {
47-
...createRouterObject(history, transitionManager),
48-
location: nextState.location,
49-
params: nextState.params
50-
}
51-
46+
const router = createRouterObject(history, transitionManager, nextState)
5247
renderProps = {
5348
...nextState,
5449
router,

0 commit comments

Comments
 (0)