我正在使用以下版本的Sapper和Svelte:
"sapper": "^0.27.0",
"svelte": "^3.0.0"
使用history.pushState()
函数更新URL后,然后导航到其他页面。history.pushState()
不要使用 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)
,但要当心!,我们不知道这样做的后果