diff --git a/.changeset/green-flowers-heal.md b/.changeset/green-flowers-heal.md new file mode 100644 index 000000000000..a348a094e1d2 --- /dev/null +++ b/.changeset/green-flowers-heal.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: prevent infinite reload when using the hash router and previewing `/index.html` diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index ea205907189a..81d0de63f0ac 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -653,7 +653,7 @@ export interface KitConfig { * What type of client-side router to use. * - `'pathname'` is the default and means the current URL pathname determines the route * - `'hash'` means the route is determined by `location.hash`. In this case, SSR and prerendering are disabled. This is only recommended if `pathname` is not an option, for example because you don't control the webserver where your app is deployed. - * It comes with some caveats: you can't use server-side rendering (or indeed any server logic), and you have to make sure that the links in your app all start with /#/, or they won't work. Beyond that, everything works exactly like a normal SvelteKit app. + * It comes with some caveats: you can't use server-side rendering (or indeed any server logic), and you have to make sure that the links in your app all start with #/, or they won't work. Beyond that, everything works exactly like a normal SvelteKit app. * * @default "pathname" * @since 2.14.0 diff --git a/packages/kit/src/runtime/client/utils.js b/packages/kit/src/runtime/client/utils.js index 2a0c35f344e9..28a06d862489 100644 --- a/packages/kit/src/runtime/client/utils.js +++ b/packages/kit/src/runtime/client/utils.js @@ -311,7 +311,7 @@ export function is_external_url(url, base, hash_routing) { } if (hash_routing) { - if (url.pathname === base + '/') { + if (url.pathname === base + '/' || url.pathname === base + '/index.html') { return false; } diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 977f1f2e879c..b80a53f668db 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -635,7 +635,7 @@ declare module '@sveltejs/kit' { * What type of client-side router to use. * - `'pathname'` is the default and means the current URL pathname determines the route * - `'hash'` means the route is determined by `location.hash`. In this case, SSR and prerendering are disabled. This is only recommended if `pathname` is not an option, for example because you don't control the webserver where your app is deployed. - * It comes with some caveats: you can't use server-side rendering (or indeed any server logic), and you have to make sure that the links in your app all start with /#/, or they won't work. Beyond that, everything works exactly like a normal SvelteKit app. + * It comes with some caveats: you can't use server-side rendering (or indeed any server logic), and you have to make sure that the links in your app all start with #/, or they won't work. Beyond that, everything works exactly like a normal SvelteKit app. * * @default "pathname" * @since 2.14.0