Fix push action -- regressed when making navigate "less pushy"

This commit is contained in:
Brent Vatne
2018-03-17 16:27:19 -04:00
parent 61cb9e342c
commit 3e1a722d29
2 changed files with 21 additions and 1 deletions

View File

@@ -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;

View File

@@ -684,6 +684,26 @@ describe('StackRouter', () => {
}).toThrow();
});
test('Push adds new routes every time', () => {
const TestRouter = StackRouter({
foo: { screen: () => <div /> },
bar: { screen: () => <div /> },
});
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: () => <div /> },