@ilha/router 0.8.12 → 0.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -22
- package/dist/rolldown.d.ts +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +10 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -36,33 +36,36 @@ router()
|
|
|
36
36
|
import { router } from "@ilha/router";
|
|
37
37
|
import { homePage, aboutPage, userPage, notFound } from "./pages";
|
|
38
38
|
|
|
39
|
-
export default
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
39
|
+
export default {
|
|
40
|
+
fetch(request: Request) {
|
|
41
|
+
const html = router()
|
|
42
|
+
.route("/", homePage)
|
|
43
|
+
.route("/about", aboutPage)
|
|
44
|
+
.route("/user/:id", userPage)
|
|
45
|
+
.route("/**", notFound)
|
|
46
|
+
.render(request.url);
|
|
47
|
+
return new Response(`<!doctype html><html><body>${html}</body></html>`, {
|
|
48
|
+
headers: { "content-type": "text/html" },
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
51
52
|
```
|
|
52
53
|
|
|
53
54
|
### SSR + Client Hydration (recommended)
|
|
54
55
|
|
|
55
56
|
```ts
|
|
56
|
-
// routes/[...].ts —
|
|
57
|
+
// routes/[...].ts — Oxide handler (SSR/prerender)
|
|
57
58
|
import { pageRouter, registry } from "ilha:pages/server";
|
|
58
59
|
import "ilha:loaders"; // ← wire server-only loaders
|
|
59
60
|
|
|
60
|
-
export default
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
61
|
+
export default {
|
|
62
|
+
async fetch(request: Request) {
|
|
63
|
+
const html = await pageRouter.renderHydratable(request.url, registry);
|
|
64
|
+
return new Response(`<!doctype html><html><body>${html}</body></html>`, {
|
|
65
|
+
headers: { "content-type": "text/html" },
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
};
|
|
66
69
|
```
|
|
67
70
|
|
|
68
71
|
```ts
|
|
@@ -154,7 +157,7 @@ Returns a `RouterBuilder`.
|
|
|
154
157
|
|
|
155
158
|
#### `.route(pattern, island, loader?)`
|
|
156
159
|
|
|
157
|
-
Registers a route. Patterns are matched in **declaration order** — first match wins. Uses [rou3](https://github.com/h3js/rou3) for matching
|
|
160
|
+
Registers a route. Patterns are matched in **declaration order** — first match wins. Uses [rou3](https://github.com/h3js/rou3) for matching.
|
|
158
161
|
|
|
159
162
|
The optional `loader` is a data-fetching function that runs before the page renders. Its return value is passed as input props to the island. The loader runs **wherever the router runs**: during SSR it executes on the server; when the route was registered in the browser (a plain SPA, hash mode, `file://`), client navigations execute it locally — no server or `/__ilha/loader` endpoint needed. Routes marked via `.markLoader()` (the SSR-split pages build) still fetch from the endpoint.
|
|
160
163
|
|
|
@@ -1013,7 +1016,7 @@ The plugin exposes separate server and client virtual modules. **Always use the
|
|
|
1013
1016
|
|
|
1014
1017
|
| Module | Exports | Use for |
|
|
1015
1018
|
| ------------------- | ------------------------ | -------------------------------------- |
|
|
1016
|
-
| `ilha:pages/server` | `pageRouter`, `registry` | SSR, prerender,
|
|
1019
|
+
| `ilha:pages/server` | `pageRouter`, `registry` | SSR, prerender, server handlers |
|
|
1017
1020
|
| `ilha:pages/client` | `pageRouter`, `registry` | Browser hydration entry |
|
|
1018
1021
|
| `ilha:loaders` | — | Server-only side-effect: wires loaders |
|
|
1019
1022
|
|
|
@@ -1099,7 +1102,7 @@ Or use the one-liner: `pageRouter.hydrate(registry)`.
|
|
|
1099
1102
|
|
|
1100
1103
|
On the **server**, loaders run inside `.renderHydratable()` / `.renderResponse()`. Their return value is serialized into `data-ilha-props` on the island element so the client can rehydrate without re-fetching.
|
|
1101
1104
|
|
|
1102
|
-
On the **client**, navigations resolve loader data before mounting the next island. Routes with a loader registered in the browser — a manual `.route(path, island, loader)` or an FS-routing `clientLoad` export — run that loader locally, with no network round-trip. Routes with only a server loader (`markLoader()` / a `load` export) fetch from the `/__ilha/loader` endpoint, served automatically by the Vite plugin (dev) and the
|
|
1105
|
+
On the **client**, navigations resolve loader data before mounting the next island. Routes with a loader registered in the browser — a manual `.route(path, island, loader)` or an FS-routing `clientLoad` export — run that loader locally, with no network round-trip. Routes with only a server loader (`markLoader()` / a `load` export) fetch from the `/__ilha/loader` endpoint, served automatically by the Vite plugin (dev) and the server adapter (production).
|
|
1103
1106
|
|
|
1104
1107
|
```
|
|
1105
1108
|
server client (navigation)
|
package/dist/rolldown.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export type { LayoutHandler, ErrorHandler, RouteSnapshot, AppError } from "./ind
|
|
|
2
2
|
export { ilhaPages, type IlhaPagesOptions } from "./plugin";
|
|
3
3
|
import { type IlhaPagesOptions } from "./plugin";
|
|
4
4
|
/** Rolldown plugin — use via `@ilha/router/rolldown`. */
|
|
5
|
-
export declare function pages(options?: IlhaPagesOptions): import("
|
|
5
|
+
export declare function pages(options?: IlhaPagesOptions): import("unplugin").RolldownPlugin<any> | import("unplugin").RolldownPlugin<any>[];
|
package/dist/ssr.d.ts
CHANGED
package/dist/ssr.js
CHANGED
|
@@ -72,7 +72,7 @@ var IlhaHandler = class {
|
|
|
72
72
|
const htmlAttrsStr = head?.htmlAttrs ?? "";
|
|
73
73
|
const langFromHead = htmlAttrsStr.match(/\blang="([^"]*)"/)?.[1];
|
|
74
74
|
return `<!doctype html>
|
|
75
|
-
<html lang="${langFromHead
|
|
75
|
+
<html lang="${langFromHead == null ? this.lang : langFromHead}"${htmlAttrsStr.replace(/\s*lang="[^"]*"/, "")}>
|
|
76
76
|
<head>
|
|
77
77
|
<meta charset="UTF-8" />
|
|
78
78
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
@@ -98,7 +98,15 @@ var IlhaHandler = class {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
async handleInner(request) {
|
|
101
|
-
|
|
101
|
+
let url;
|
|
102
|
+
try {
|
|
103
|
+
url = new URL(request.url);
|
|
104
|
+
} catch {
|
|
105
|
+
return new Response("Bad Request", {
|
|
106
|
+
status: 400,
|
|
107
|
+
headers: { "content-type": "text/plain;charset=utf-8" }
|
|
108
|
+
});
|
|
109
|
+
}
|
|
102
110
|
if (url.pathname === "/__ilha/loader") {
|
|
103
111
|
if (request.method !== "GET" && request.method !== "HEAD") return new Response(JSON.stringify({
|
|
104
112
|
kind: "error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ilha/router",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.13",
|
|
4
4
|
"description": "A tiny SPA router for Ilha",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"frontend",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown && tsc -p tsconfig.build.json",
|
|
64
|
+
"cleanup": "rimraf dist node_modules",
|
|
64
65
|
"test": "bun test"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
@@ -68,10 +69,10 @@
|
|
|
68
69
|
"unplugin": "3.3.0"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
|
-
"ilha": "0.10.
|
|
72
|
+
"ilha": "0.10.3",
|
|
72
73
|
"vite": "^8.2.0"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
|
-
"ilha": ">=0.10.
|
|
76
|
+
"ilha": ">=0.10.3"
|
|
76
77
|
}
|
|
77
78
|
}
|