Skip to content

Commit

Permalink
Merge pull request #5 from shopgate/PWA-159--Pass-props-through-Route
Browse files Browse the repository at this point in the history
PWA-159 Arbitrary props are passed through Route
  • Loading branch information
CarinaMack committed Mar 21, 2018
2 parents c2d5c26 + fe92883 commit eda5038
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`<Router /> should notify previous route to hide and new one to show 1`]
},
"_eventsCount": 4,
"_maxListeners": undefined,
"domain": null,
"findHistoryIndexByKey": [Function],
"getActive": [Function],
"getLength": [Function],
Expand Down Expand Up @@ -106,6 +107,7 @@ exports[`<Router /> should notify route about initial location 1`] = `
},
"_eventsCount": 4,
"_maxListeners": undefined,
"domain": null,
"findHistoryIndexByKey": [Function],
"getActive": [Function],
"getLength": [Function],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`<Route /> should create new instance when notified 1`] = `
"id": 123,
}
}
path="category/:id"
setComponentRef={[Function]}
setRef={[Function]}
>
Expand All @@ -25,6 +26,7 @@ exports[`<Route /> should create new instance when notified 1`] = `
"id": 123,
}
}
path="category/:id"
/>
</div>
</RouteContent>
Expand All @@ -47,6 +49,7 @@ exports[`<Route /> should keep two components when going forward 1`] = `
"id": 123,
}
}
path="category/:id"
setComponentRef={[Function]}
setRef={[Function]}
>
Expand All @@ -57,6 +60,7 @@ exports[`<Route /> should keep two components when going forward 1`] = `
"id": 123,
}
}
path="category/:id"
/>
</div>
</RouteContent>
Expand All @@ -67,6 +71,7 @@ exports[`<Route /> should keep two components when going forward 1`] = `
"id": 456,
}
}
path="category/:id"
setComponentRef={[Function]}
setRef={[Function]}
>
Expand All @@ -77,6 +82,7 @@ exports[`<Route /> should keep two components when going forward 1`] = `
"id": 456,
}
}
path="category/:id"
/>
</div>
</RouteContent>
Expand Down Expand Up @@ -110,6 +116,7 @@ exports[`<Route /> should remove route instance when going back 1`] = `
"id": 456,
}
}
path="category/:id"
setComponentRef={[Function]}
setRef={[Function]}
>
Expand All @@ -120,6 +127,7 @@ exports[`<Route /> should remove route instance when going back 1`] = `
"id": 456,
}
}
path="category/:id"
/>
</div>
</RouteContent>
Expand Down
5 changes: 3 additions & 2 deletions libraries/common/components/Router/components/Route/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class Route extends Component {
location,
};

const { component: c, ...otherProps } = this.props;

const componentProps = {
key: location.key || location.immutableKey || 'root',
setRef: (element) => {
Expand All @@ -170,10 +172,9 @@ class Route extends Component {
function componentDidUpdate(prevProps, prevState) {
originalComponentDidUpdate(prevProps, prevState);
};

newHostedComponent.componentInstance.enableTracking = this.enableTracking;
},
params,
...otherProps,
};

if (this.wrappedComponent) {
Expand Down
20 changes: 16 additions & 4 deletions libraries/common/components/Router/components/Route/spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ describe('<Route />', () => {
wrapper.update();
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(MockComponent).length).toEqual(1);
expect(wrapper.find(MockComponent).props()).toEqual({ params: { id: 123 } });
expect(wrapper.find(MockComponent).props()).toEqual({
params: { id: 123 },
path: 'category/:id',
});
});

it('should remove route instance when going back', () => {
Expand Down Expand Up @@ -99,7 +102,10 @@ describe('<Route />', () => {

expect(wrapper).toMatchSnapshot();
expect(wrapper.find(MockComponent).length).toEqual(1);
expect(wrapper.find(MockComponent).props()).toEqual({ params: { id: 456 } });
expect(wrapper.find(MockComponent).props()).toEqual({
params: { id: 456 },
path: 'category/:id',
});
});

it('should keep two components when going forward', () => {
Expand Down Expand Up @@ -127,7 +133,13 @@ describe('<Route />', () => {
wrapper.update();
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(MockComponent).length).toEqual(2);
expect(wrapper.find(MockComponent).at(0).props()).toEqual({ params: { id: 123 } });
expect(wrapper.find(MockComponent).at(1).props()).toEqual({ params: { id: 456 } });
expect(wrapper.find(MockComponent).at(0).props()).toEqual({
params: { id: 123 },
path: 'category/:id',
});
expect(wrapper.find(MockComponent).at(1).props()).toEqual({
params: { id: 456 },
path: 'category/:id',
});
});
});

0 comments on commit eda5038

Please sign in to comment.