Skip to content

data-sveltekit-preload-code runs the universal hook reroute function, missing docs #15032

@ayyash

Description

@ayyash

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions