data-sveltekit-preload-code runs the universal hook reroute function, missing docs
Describe the problem
I was testing with reroute function, but I noticed that it ran multiple time when data-sveltekit-preload-code="eager" was added to the app.html. (there were multiple navigation links on the page). Is that by design?
in app.html:
<body data-sveltekit-preload-code="eager">
In hook.ts
export const reroute: Reroute = ({ url }) => {
// save in authstate then return
if (url.pathname.indexOf(Config.Auth.loginRoute) < 0) {
console.log(url.pathname, 'catch reroute here');
AuthState.redirectUrl = url.pathname;
}
// do something and return
return reroutePath(url.pathname);
};
Describe the proposed solution
If it is by design, it should be documented because I was under the assumption it just preloads code without running anything specific
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
How could we preload code for a route without knowing which route to preload the code for?
yes but for someone who uses the black box, it really saves the day just mentioning it
I'm having a hard time seeing when it would be an unpleasant surprise for someone that their reroute hook is being run, even if for some reason they weren't expecting it to be in this case. The docs do mention that it is assumed to be a pure, idempotent function. Saying anything further here in the docs seems like a distraction.
I had a hard time, took me an hour to realize the reason my site was not acting properly is that i was placing a statement in reroute hook, when I finally figured it out, I moved out the statement