Don't use params from unrelated action when initializing nav state (#3094)

`TabRouter.getStateForAction` has some code at the start to initialize an empty nav state before handling any action. This initialization is achieved by passing `INIT` actions to all child routes. However, the code strangely also passes these child routes the params that were given to the action. The initialization should be separate from the processing of the action.
This commit is contained in:
Ashoat Tevosyan
2017-12-12 03:00:33 -08:00
parent 8d0f086a8a
commit b44d7e117b
2 changed files with 5 additions and 8 deletions

View File

@@ -61,9 +61,7 @@ export default (
const routes = order.map((routeName: string) => {
const tabRouter = tabRouters[routeName];
if (tabRouter) {
const childAction = NavigationActions.init({
...(action.params ? { params: action.params } : {}),
});
const childAction = NavigationActions.init();
return {
...tabRouter.getStateForAction(childAction),
key: routeName,

View File

@@ -215,7 +215,6 @@ describe('TabRouter', () => {
const navAction = {
type: NavigationActions.NAVIGATE,
routeName: 'Baz',
params: { foo: '42', bar: '43' },
};
let state = router.getStateForAction(navAction);
expect(state).toEqual({
@@ -227,8 +226,8 @@ describe('TabRouter', () => {
key: 'Baz',
routeName: 'Baz',
routes: [
{ key: 'Boo', routeName: 'Boo', params: { foo: '42', bar: '43' } },
{ key: 'Bar', routeName: 'Bar', params: { foo: '42', bar: '43' } },
{ key: 'Boo', routeName: 'Boo' },
{ key: 'Bar', routeName: 'Bar' },
],
},
],
@@ -248,8 +247,8 @@ describe('TabRouter', () => {
key: 'Baz',
routeName: 'Baz',
routes: [
{ key: 'Boo', routeName: 'Boo', params: { foo: '42', bar: '43' } },
{ key: 'Bar', routeName: 'Bar', params: { foo: '42', bar: '43' } },
{ key: 'Boo', routeName: 'Boo' },
{ key: 'Bar', routeName: 'Bar' },
],
});
});