Open vnphanquang opened 10 months ago
Workaround for now
// src/hooks.js
/** @type {Record<string, string>} */
const translated = {
'/en': '/',
};
/** @type {import('@sveltejs/kit').Reroute} */
export function reroute({ url }) {
console.log(`REROUTE`, url.toString());
let suffix = '';
let pathname = url.pathname;
const segments = pathname.split('/');
const lastSegment = segments.at(-1);
if (lastSegment && /\.\w+$/.test(lastSegment)) {
suffix = '/' + lastSegment;
pathname = segments.slice(0, -1).join('/');
}
if (pathname in translated) {
return translated[pathname] + suffix;
}
}
Thanks, @vnphanquang! I've been facing the same behaviour and wasn't sure what is going on. I also noticed reroute
runs for every mouse move over link, not on enter only.
@alesvaupotic yeah if link options is set up for preloading, hovering on links might trigger client-side fetching for page data, which should hit reroute
hook.
Describe the bug
Following the new reroute hook from https://github.com/sveltejs/kit/pull/11537, invalidating load function(s) on a "rerouted" page will result in a 404 error for
__data.json?x-sveltekit-invalidated=...
(invokinginvalidate
orinvalidateAll
from$app/navigation
).Please note that this does NOT happen in build output from my test with
preview
script and@sveltejs/adapter-static
.For example, with the following
reroute
setup......, calling
invalidateAll
while on/en
page will cause kit to throw the aforementioned 404...Reproduction
Please follow the steps below:
dev
script,http://localhost:5173/en
,invalidate
button,Logs
System Info
Severity
annoyance
Additional Information
This might be related to some other open issues about
__data.json