mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-12 09:21:09 +08:00
Fix push action -- regressed when making navigate "less pushy"
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 /> },
|
||||
|
||||
Reference in New Issue
Block a user