Skip to content

Commit e7d46c4

Browse files
authored
added options reset
1 parent a315abb commit e7d46c4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const storage = [];
22

3-
module.exports = ({ history, limit = 20 }) => ({
3+
module.exports = ({ history, reset = true, limit = 20 }) => ({
44
start: () => {
55
if(history.action === 'PUSH') {
66
storage.push([
@@ -18,8 +18,14 @@ module.exports = ({ history, limit = 20 }) => ({
1818

1919
if(history.action === 'POP' && storage.length) {
2020
position = storage.pop();
21+
22+
window.scrollTo(...position);
23+
} else {
24+
const { location: { state } } = history;
25+
26+
if(reset || (state && state.resetScroll)) {
27+
window.scrollTo(...position);
28+
}
2129
}
22-
23-
window.scrollTo(...position);
2430
}
25-
});
31+
});

0 commit comments

Comments
 (0)