Reactive LayoutServerData URL path in Svelte

  • 1 min read
  • Tags: 
  • svelte
  • aha

So when using Svelte 5, if you want to update the Layout from the URL path, you should use in your load function the url:

// +layout.server.ts
export const load = async ({ url, }) => {
    if (url.pathname.endsWith("login") || url.pathname.endsWith("signup")) {
        [...]
    }
}

And not:

// +layout.server.ts
export const load = async ({ request, }) => {
    if (request.url.endsWith("login") || request.url.endsWith("signup")) {
        [...]
    }
}

Which is not reactive.

see doc here.