使用serviceworker回退处理程序时相对模块url的问题



当将svelte kit与service worker配置结合使用以在脱机时返回回退路由时,对于每个请求/test/, service worker都会用预渲染的html来响应/(备用路由)。如果我们查看预渲染的HTML,我们会看到模块被预加载了相对url:

<link rel="modulepreload" href="./_app/immutable/start-5e8ef69f.js">
<link rel="modulepreload" href="./_app/immutable/chunks/index-cc4e69a6.js">
<link rel="modulepreload" href="./_app/immutable/chunks/stores-e8997401.js">
<link rel="modulepreload" href="./_app/immutable/chunks/preload-helper-b21cceae.js">
<link rel="modulepreload" href="./_app/immutable/chunks/store-535059b2.js">

这里的问题是,浏览器解决了这些url到/test/_app/immutable/start-5e8ef69f.js, etc...,不会找到这些资产。如果这些url是绝对的,这个问题就不存在了。这是故意的还是我做错了?

我用kit.config.paths.assets找到了它。svelte.config.js中的配置选项。设置它将在所有路径前添加。

最新更新