Skip to content

Commit 6141636

Browse files
committed
[breaking] remove per-page router option
1 parent d6d492a commit 6141636

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

.changeset/rare-eels-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[breaking] remove per-page `router` option

documentation/docs/11-page-options.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,7 @@ title: Page options
44

55
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.
66

7-
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.
8-
9-
If both are specified, per-page settings override per-app settings in case of conflicts.
10-
11-
### router
12-
13-
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.
14-
15-
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:
16-
17-
```html
18-
<script context="module">
19-
export const router = false;
20-
</script>
21-
```
22-
23-
Note that this will disable client-side routing for any navigation from this page, regardless of whether the router is already active.
7+
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.
248

259
### hydrate
2610

packages/kit/src/runtime/server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export async function respond(incoming, options, state = {}) {
9797
options,
9898
state,
9999
$session: await options.hooks.getSession(request),
100-
page_config: { router: true, hydrate: true },
100+
page_config: { hydrate: true },
101101
stuff: {},
102102
status: 200,
103103
branch: [],

packages/kit/src/runtime/server/page/render.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { create_prerendering_url_proxy } from './utils.js';
1414
* options: import('types/internal').SSRRenderOptions;
1515
* state: import('types/internal').SSRRenderState;
1616
* $session: any;
17-
* page_config: { hydrate: boolean, router: boolean };
17+
* page_config: { hydrate: boolean };
1818
* status: number;
1919
* error?: Error;
2020
* url: URL;
@@ -151,7 +151,7 @@ export async function render_response({
151151
.map((dep) => `\n\t<link${styles.has(dep) ? ' disabled' : ''} rel="stylesheet" href="${options.prefix + dep}">`)
152152
.join('');
153153

154-
if (page_config.router || page_config.hydrate) {
154+
if (page_config.hydrate) {
155155
head += Array.from(js)
156156
.map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
157157
.join('');
@@ -165,7 +165,6 @@ export async function render_response({
165165
session: ${try_serialize($session, (error) => {
166166
throw new Error(`Failed to serialize session data: ${error.message}`);
167167
})},
168-
route: ${!!page_config.router},
169168
spa: ${!ssr},
170169
trailing_slash: ${s(options.trailing_slash)},
171170
hydrate: ${ssr && page_config.hydrate ? `{

packages/kit/src/runtime/server/page/respond.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export async function respond(opts) {
3434
...opts,
3535
branch: [],
3636
page_config: {
37-
hydrate: true,
38-
router: true
37+
hydrate: true
3938
},
4039
status: 200,
4140
url: request.url,
@@ -247,12 +246,17 @@ function get_page_config(leaf, options) {
247246
// TODO remove for 1.0
248247
if ('ssr' in leaf) {
249248
throw new Error(
250-
'`export const ssr` has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
249+
'`export const ssr` has been removed — use the `handle` hook instead: https://kit.svelte.dev/docs#hooks-handle'
250+
);
251+
}
252+
253+
if ('router' in leaf) {
254+
throw new Error(
255+
'`export const router` has been removed — use `beforeNavigate` instead: https://kit.svelte.dev/docs#modules-$app-navigation'
251256
);
252257
}
253258

254259
return {
255-
router: 'router' in leaf ? !!leaf.router : options.router,
256260
hydrate: 'hydrate' in leaf ? !!leaf.hydrate : options.hydrate
257261
};
258262
}

packages/kit/src/runtime/server/page/respond_with_error.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ export async function respond_with_error({
7272
state,
7373
$session,
7474
page_config: {
75-
hydrate: options.hydrate,
76-
router: options.router
75+
hydrate: options.hydrate
7776
},
7877
stuff: error_loaded.stuff,
7978
status,

0 commit comments

Comments
 (0)