2

有两件事是动态的:导航 div 和内容 div。我的计划不是同时存储两者,而是将整个 body div 存储在pushState.

存储数据的正确方法是什么?我尝试了以下哪些产品出错Uncaught DataCloneError: Failed to execute 'pushState' on 'History': An object could not be cloned.

history.pushState($('.body-content'), newTitle, newURL);

这就是它处理 popstate 的方式,未经测试:

    window.onpopstate = function (event) {
        updateContent(event.state);
    };

    function updateContent(data) {
        if (data == null)
            return;

        $('.body-content').html(data);
    }

编辑:添加.html()到 jQuery 选择器工作:

history.pushState($('.body-content').html(), 'testTitle', getURL(newQuery));

但是popstates仍然不一致,目前正在进一步研究。我怀疑数据在 div 的嵌套中被恢复到错误的级别,并且 Leaflet 地图将有陈旧的变量,这些变量也应该保存在 pushState 中。

4

0 回答 0