diff --git a/packages/react-navigation/src/routers/StackRouter.js b/packages/react-navigation/src/routers/StackRouter.js index 7f035d3a..fb802c53 100644 --- a/packages/react-navigation/src/routers/StackRouter.js +++ b/packages/react-navigation/src/routers/StackRouter.js @@ -206,7 +206,7 @@ export default (routeConfigs, stackConfig = {}) => { } }); - if (lastRouteIndex !== -1) { + if (action.type !== NavigationActions.PUSH && lastRouteIndex !== -1) { // If index is unchanged and params are not being set, leave state identity intact if (state.index === lastRouteIndex && !action.params) { return state; diff --git a/packages/react-navigation/src/routers/__tests__/StackRouter-test.js b/packages/react-navigation/src/routers/__tests__/StackRouter-test.js index bae0fba2..31606bbf 100644 --- a/packages/react-navigation/src/routers/__tests__/StackRouter-test.js +++ b/packages/react-navigation/src/routers/__tests__/StackRouter-test.js @@ -684,6 +684,26 @@ describe('StackRouter', () => { }).toThrow(); }); + test('Push adds new routes every time', () => { + const TestRouter = StackRouter({ + foo: { screen: () =>
}, + bar: { screen: () =>
}, + }); + const initState = TestRouter.getStateForAction(NavigationActions.init()); + const pushedState = TestRouter.getStateForAction( + NavigationActions.push({ routeName: 'bar' }), + initState + ); + expect(pushedState.index).toEqual(1); + expect(pushedState.routes[1].routeName).toEqual('bar'); + const secondPushedState = TestRouter.getStateForAction( + NavigationActions.push({ routeName: 'bar' }), + pushedState + ); + expect(secondPushedState.index).toEqual(2); + expect(secondPushedState.routes[2].routeName).toEqual('bar'); + }); + test('Navigate backwards with key removes leading routes', () => { const TestRouter = StackRouter({ foo: { screen: () =>
},