将后退按钮无法在历史记录施加功能之后工作



我正在使用以下版本的Sapper和Svelte:

"sapper": "^0.27.0",
"svelte": "^3.0.0"

使用history.pushState()函数更新URL后,然后导航到其他页面。history.pushState()

更改了后退按钮,请返回URL。

不要使用 history.pushState() - 这等同于在Svelte中做自己的element.appendChild(document.createElement('div'))。而是使用Sapper的goto函数:https://sapper.svelte.dev/docs#goto_href_options

我认为这是sapper https://github.com/sveltejs/sapper/sapper/sissues/791

的问题

提到的解决方法是将{id:0}作为 data 传递给history.pushState()。例如

history.pushState({id:0}, '', url)

,但要当心!,我们不知道这样做的后果

最新更新