fix off by 1 error in navigation history

This commit is contained in:
Jeremy Kauffman 2017-08-31 08:59:29 -04:00
parent f12e3551e2
commit a9113369ef

View file

@ -41,17 +41,12 @@ reducers[types.HISTORY_NAVIGATE] = (state, action) => {
let newState = {}; let newState = {};
const path = action.data.url, const path = action.data.url;
previousIndex = index - 1;
// Check for duplicated // Check for duplicated
if (action.data.index >= 0) { if (action.data.index >= 0) {
newState.index = action.data.index; newState.index = action.data.index;
} else if ( } else if (!stack[index] || stack[index].path !== path) {
previousIndex === -1 ||
!stack[previousIndex] ||
stack[previousIndex].path !== path
) {
newState.stack = [...stack.slice(0, index + 1), { path, scrollY: 0 }]; newState.stack = [...stack.slice(0, index + 1), { path, scrollY: 0 }];
newState.index = newState.stack.length - 1; newState.index = newState.stack.length - 1;
} }