【发布时间】:2019-08-03 17:26:12
【问题描述】:
我正在使用以下版本的 Sapper 和 Svelte:
"sapper": "^0.27.0",
"svelte": "^3.0.0"
使用history.pushState() 函数更新网址后,然后导航到其他页面。后退按钮没有返回到history.pushState()更改的url
【问题讨论】:
我正在使用以下版本的 Sapper 和 Svelte:
"sapper": "^0.27.0",
"svelte": "^3.0.0"
使用history.pushState() 函数更新网址后,然后导航到其他页面。后退按钮没有返回到history.pushState()更改的url
【问题讨论】:
不要使用 history.pushState() — 这相当于在 Svelte 中使用自己的 element.appendChild(document.createElement('div'))。相反,使用 Sapper 的 goto 函数:https://sapper.svelte.dev/docs#goto_href_options
【讨论】:
input 字段更改的 url。
goto(`/profile/edit?id=${profile_id}`, { replaceState: true })。我得到了想要的结果,但失去了表单字段的焦点。在goto() 和replaceState 之后,我的领域如何保持焦点?
autofocus。
import { goto } from '@sapper/app'
我认为这是工兵https://github.com/sveltejs/sapper/issues/791 的问题
提到的解决方法是将{id:0} 作为数据 传递给history.pushState()。例如
history.pushState({id:0}, '', url)
但要小心!,我们不知道这样做的后果
【讨论】: