Skip to content

Commit

Permalink
Merge pull request #10 from lerit/master
Browse files Browse the repository at this point in the history
fix go bug and history mode event listen
  • Loading branch information
kallsave committed Jun 15, 2023
2 parents fa60322 + e37acfd commit 1226113
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/history/history-state-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import historyStack from './history-stack'
import { BACK, FORWARD } from './history-direction-name'

const historyStateEvent = new Events()

window.addEventListener('hashchange', () => {
function historyChangeEvt(){
if (historyStack.getByIndex(1) === window.location.href) {
historyStateEvent.emit(BACK)
historyStateEvent.emit(BACK);
} else {
historyStateEvent.emit(FORWARD)
historyStateEvent.emit(FORWARD);
}
})
}

window.addEventListener('hashchange', historyChangeEvt);
window.addEventListener('popstate', historyChangeEvt);

export default historyStateEvent
4 changes: 2 additions & 2 deletions src/router-middle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ const routerMiddle = (Vue, config) => {

router.go = (n) => {
// dev: go(n > 1)会导致方向判断错误
if (n > 1) {
if (n > 0) {
direction = FORWARD
} else if (n < -1) {
} else if (n < 0) {
direction = BACK
historyStack.removeBackByIndex(-n)
config.setHistoryStack(historyStack.getStore())
Expand Down

0 comments on commit 1226113

Please sign in to comment.