瀏覽器歷史,判斷是點選了後退按鈕還是前進按鈕

zyip發表於2016-03-03
var history = this.state.history,
            pages = this.state.pages,
            l = history.length,
            hash = window.location.hash,
            position = "center";

        if (l === 0) {
            history.push(hash);
        } else if (hash === history[l - 2]) {
            history.pop();
            position = "left";
        } else {
            history.push(hash);
            position = "right";
        }

https://github.com/zyip/react/blob/master/src/main.js

 

相關文章