diff --git a/.changeset/rare-eels-run.md b/.changeset/rare-eels-run.md new file mode 100644 index 000000000000..94c5fecb9542 --- /dev/null +++ b/.changeset/rare-eels-run.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[breaking] remove per-page `router` option diff --git a/documentation/docs/11-page-options.md b/documentation/docs/11-page-options.md index 82a95eee0e82..e8e3d16fd018 100644 --- a/documentation/docs/11-page-options.md +++ b/documentation/docs/11-page-options.md @@ -4,23 +4,7 @@ title: Page options By default, SvelteKit will render any component first on the server and send it to the client as HTML. It will then render the component again in the browser to make it interactive in a process called **hydration**. For this reason, you need to ensure that components can run in both places. SvelteKit will then initialise a [**router**](#routing) that takes over subsequent navigations. -You can control each of these on a per-app or per-page basis. Note that each of the per-page settings use [`context="module"`](https://svelte.dev/docs#script_context_module), and only apply to page components, _not_ [layout](#layouts) components. - -If both are specified, per-page settings override per-app settings in case of conflicts. - -### router - -SvelteKit includes a [client-side router](#appendix-routing) that intercepts navigations (from the user clicking on links, or interacting with the back/forward buttons) and updates the page contents, rather than letting the browser handle the navigation by reloading. - -In certain circumstances you might need to disable [client-side routing](#appendix-routing) with the app-wide [`router` config option](#configuration-router) or the page-level `router` export: - -```html - -``` - -Note that this will disable client-side routing for any navigation from this page, regardless of whether the router is already active. +Note that each of the per-page settings use [`context="module"`](https://svelte.dev/docs#script_context_module), and only apply to page components, _not_ [layout](#layouts) components. If both per-page and per-app settings are specified, the per-page settings override per-app settings in case of conflicts. ### hydrate diff --git a/packages/kit/src/runtime/client/renderer.js b/packages/kit/src/runtime/client/renderer.js index 5a5856d5a5d8..7e47decf45a2 100644 --- a/packages/kit/src/runtime/client/renderer.js +++ b/packages/kit/src/runtime/client/renderer.js @@ -323,15 +323,6 @@ export class Renderer { this.loading.id = null; this.autoscroll = true; this.updating = false; - - if (!this.router) return; - - const leaf_node = navigation_result.state.branch[navigation_result.state.branch.length - 1]; - if (leaf_node && leaf_node.module.router === false) { - this.router.disable(); - } else { - this.router.enable(); - } } /** diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 9692866bbfa7..eaf3d663e78c 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -97,7 +97,7 @@ export async function respond(incoming, options, state = {}) { options, state, $session: await options.hooks.getSession(request), - page_config: { router: true, hydrate: true }, + page_config: { hydrate: true }, stuff: {}, status: 200, branch: [], diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js index db66d9949841..5d9180a7154f 100644 --- a/packages/kit/src/runtime/server/page/render.js +++ b/packages/kit/src/runtime/server/page/render.js @@ -14,7 +14,7 @@ import { create_prerendering_url_proxy } from './utils.js'; * options: import('types/internal').SSRRenderOptions; * state: import('types/internal').SSRRenderState; * $session: any; - * page_config: { hydrate: boolean, router: boolean }; + * page_config: { hydrate: boolean }; * status: number; * error?: Error; * url: URL; @@ -151,7 +151,7 @@ export async function render_response({ .map((dep) => `\n\t`) .join(''); - if (page_config.router || page_config.hydrate) { + if (page_config.hydrate) { head += Array.from(js) .map((dep) => `\n\t`) .join(''); @@ -165,7 +165,6 @@ export async function render_response({ session: ${try_serialize($session, (error) => { throw new Error(`Failed to serialize session data: ${error.message}`); })}, - route: ${!!page_config.router}, spa: ${!ssr}, trailing_slash: ${s(options.trailing_slash)}, hydrate: ${ssr && page_config.hydrate ? `{ diff --git a/packages/kit/src/runtime/server/page/respond.js b/packages/kit/src/runtime/server/page/respond.js index c38fb7264365..8c9f506f7406 100644 --- a/packages/kit/src/runtime/server/page/respond.js +++ b/packages/kit/src/runtime/server/page/respond.js @@ -34,8 +34,7 @@ export async function respond(opts) { ...opts, branch: [], page_config: { - hydrate: true, - router: true + hydrate: true }, status: 200, url: request.url, @@ -247,12 +246,17 @@ function get_page_config(leaf, options) { // TODO remove for 1.0 if ('ssr' in leaf) { throw new Error( - '`export const ssr` has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle' + '`export const ssr` has been removed — use the `handle` hook instead: https://kit.svelte.dev/docs#hooks-handle' + ); + } + + if ('router' in leaf) { + throw new Error( + '`export const router` has been removed — use `beforeNavigate` instead: https://kit.svelte.dev/docs#modules-$app-navigation' ); } return { - router: 'router' in leaf ? !!leaf.router : options.router, hydrate: 'hydrate' in leaf ? !!leaf.hydrate : options.hydrate }; } diff --git a/packages/kit/src/runtime/server/page/respond_with_error.js b/packages/kit/src/runtime/server/page/respond_with_error.js index cfd05eec5dc4..b2a4c4e1dbaa 100644 --- a/packages/kit/src/runtime/server/page/respond_with_error.js +++ b/packages/kit/src/runtime/server/page/respond_with_error.js @@ -72,8 +72,7 @@ export async function respond_with_error({ state, $session, page_config: { - hydrate: options.hydrate, - router: options.router + hydrate: options.hydrate }, stuff: error_loaded.stuff, status,