#16981·kit

仅在Navigate召回存在之前, 注册未加载的收听器

作者: Nic-Polumeyv创建于 2026年8月31日更新于 2026年9月8日

`_start_router` 无条件地注册 `beforeunload` (packages/kit/src/runtime/client/client.js:3164, 2eed63867)。Firefox 会将具有 `beforeunload` 监听器的任何页面排除在 bfcache 中,因此即使不存在 `beforeNavigate` 回调来运行,SvelteKit 应用程序也会在该处丢失后退/前进缓存。监听器存在于 `beforeNavigate` 中,以触发 `type: 'leave'`,并重置 `history.scrollRestoration`;`persist_state` 已经在 `visibilitychange` 中运行,MDN 建议用于保存状态。在第一个 `beforeNavigate` 回调注册时添加监听器,在最后一个回调取消注册时移除监听器,并将 `scrollRestoration` 重置到 `pagehide`。