You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A typed helper that returns the layout function as-is. Use it instead of the `satisfies LayoutHandler` cast for a cleaner, import-light syntax.
327
+
328
+
```ts
329
+
// src/pages/+layout.ts
330
+
import { defineLayout } from"@ilha/router";
331
+
importilha, { html } from"ilha";
332
+
333
+
exportdefaultdefineLayout((children) =>
334
+
ilha.render(
335
+
() =>html`
336
+
<nav>
337
+
<a href="/">Home</a>
338
+
<a href="/about">About</a>
339
+
</nav>
340
+
<main>${children}</main>
341
+
`,
342
+
),
343
+
);
344
+
```
345
+
346
+
Equivalent to annotating with `satisfies LayoutHandler` but requires no explicit type import.
347
+
348
+
---
349
+
324
350
### `wrapError(handler, page)`
325
351
326
352
Wraps a page island with an error boundary. If the page throws during SSR (`.toString()`), the `handler` receives the error and current route snapshot and returns a fallback island. Also intercepts errors during `.mount()` for client-side resilience.
@@ -367,6 +393,9 @@ interface HydrateOptions {
367
393
root?:Element;
368
394
target?:string|Element;
369
395
}
396
+
397
+
// Helper — returns fn as-is with LayoutHandler type enforced
398
+
function defineLayout(fn:LayoutHandler):LayoutHandler;
370
399
```
371
400
372
401
---
@@ -467,8 +496,28 @@ A `+layout.ts` wraps every page in its directory and all subdirectories. Layouts
467
496
468
497
```ts
469
498
// src/pages/+layout.ts
470
-
import { html } from"ilha";
499
+
import { defineLayout } from"@ilha/router";
500
+
importilha, { html } from"ilha";
501
+
502
+
exportdefaultdefineLayout((children) =>
503
+
ilha.render(
504
+
() =>html`
505
+
<nav>
506
+
<a href="/">Home</a>
507
+
<a href="/about">About</a>
508
+
</nav>
509
+
<main>${children}</main>
510
+
`,
511
+
),
512
+
);
513
+
```
514
+
515
+
Alternatively, using the explicit type annotation:
516
+
517
+
```ts
518
+
// src/pages/+layout.ts — using satisfies (equivalent)
0 commit comments