Skip to content

Commit

Permalink
feat: Match withRouter props signature for route components (#230)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Route components no longer receive spread-out match.
  • Loading branch information
taion committed Jan 11, 2019
1 parent ff30f47 commit 7304e90
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/createElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isResolved } from './ResolverUtils';

export default function createElements(routeMatches, Components, matchData) {
return routeMatches.map((match, i) => {
const { route } = match;
const { router, route } = match;

const Component = Components[i];
const data = matchData[i];
Expand All @@ -20,7 +20,7 @@ export default function createElements(routeMatches, Components, matchData) {
return route.render({
match,
Component: isComponentResolved ? Component : null,
props: areDataResolved ? { ...match, data } : null,
props: areDataResolved ? { match, router, data } : null,
data: areDataResolved ? data : null,
});
}
Expand All @@ -42,6 +42,6 @@ export default function createElements(routeMatches, Components, matchData) {
return null;
}

return <Component {...match} data={data} />;
return <Component match={match} router={router} data={data} />;
});
}
1 change: 0 additions & 1 deletion src/utils/resolveRenderArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default async function* resolveRenderArgs({
const augmentedMatch = {
...match,
routes,
match, // For symmetry with withRouter.
router, // Convenience access for route components.
context: matchContext,
};
Expand Down
8 changes: 4 additions & 4 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('render', () => {
},
{
path: 'baz/:qux',
Component: ({ params }) => (
<div className="baz">{params.qux}</div>
Component: ({ match }) => (
<div className="baz">{match.params.qux}</div>
),
},
],
Expand Down Expand Up @@ -95,8 +95,8 @@ describe('render', () => {
},
{
path: 'qux/:quux',
Component: ({ params }) => (
<div className="qux">{params.quux}</div>
Component: ({ match }) => (
<div className="qux">{match.params.quux}</div>
),
},
],
Expand Down
8 changes: 5 additions & 3 deletions test/server/getFarceResult.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('getFarceResult', () => {
},
{
path: 'baz/:qux',
Component: ({ params }) => <div className="baz">{params.qux}</div>,
Component: ({ match }) => (
<div className="baz">{match.params.qux}</div>
),
},
],
},
Expand Down Expand Up @@ -72,8 +74,8 @@ describe('getFarceResult', () => {
},
{
path: 'qux/:quux',
Component: ({ params }) => (
<div className="qux">{params.quux}</div>
Component: ({ match }) => (
<div className="qux">{match.params.quux}</div>
),
},
],
Expand Down

0 comments on commit 7304e90

Please sign in to comment.