Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 42d6901

Browse files
committed
Fix SwitchRouter depending on previous state to be defined when performing navigate
1 parent 195786c commit 42d6901

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/routers/SwitchRouter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ export default (routeConfigs, config = {}) => {
9393
if (backBehavior !== 'history') {
9494
return nextState;
9595
}
96-
let nextRouteKeyHistory = prevState.routeKeyHistory;
96+
let nextRouteKeyHistory = prevState ? prevState.routeKeyHistory : [];
9797
if (action.type === NavigationActions.NAVIGATE) {
98-
nextRouteKeyHistory = [...prevState.routeKeyHistory]; // copy
98+
nextRouteKeyHistory = [...nextRouteKeyHistory]; // copy
9999
const keyToAdd = nextState.routes[nextState.index].key;
100100
nextRouteKeyHistory = nextRouteKeyHistory.filter(k => k !== keyToAdd); // dedup
101101
nextRouteKeyHistory.push(keyToAdd);
102102
} else if (action.type === NavigationActions.BACK) {
103-
nextRouteKeyHistory = [...prevState.routeKeyHistory]; // copy
103+
nextRouteKeyHistory = [...nextRouteKeyHistory]; // copy
104104
nextRouteKeyHistory.pop();
105105
}
106106
return {

0 commit comments

Comments
 (0)