urlを切り替えてページを更新しない

1060 ワード

    changeHistory (search) {
        var query = '', href = '';
        for (var i in search) {
            !search[i] && delete search[i];
            query += search[i] ? '&' + i + '=' + search[i] : '';
        }

        href = query ? '?' + query.substring(1, query.length) : location.pathname;
        !window.history.pushState ? location.href = href : window.history.pushState(search, null, href);
    }

if(!window.history.pushState) return false;
ページを前に戻します
        if (window.history && window.history.pushState) {
            window.onpopstate = function (event) {
                console.log(event);
                console.log(that.condition);
                if (window.location.pathname == '/goods/all') {
                    that.data = JSON.parse(JSON.stringify(event.state));
                    that.jq.extend(event.state, that.defaultData);
                    that.submit();
                }
            };

        }