@ilha/router 0.4.3 → 0.5.1
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 +28 -14
- package/dist/{index-CJT0h4u4.d.ts → index-DZA_1KrG.d.ts} +31 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin-BizQQLsn.d.ts +28 -0
- package/dist/{plugin-BMk5Ey9X.js → plugin-C-TVH3XD.js} +37 -9
- package/dist/rolldown.d.ts +2 -2
- package/dist/rolldown.js +2 -2
- package/dist/rspack.d.ts +2 -2
- package/dist/rspack.js +2 -2
- package/dist/{src-BqAWh426.js → src-BP38YTMC.js} +16 -3
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/package.json +2 -2
- package/dist/plugin-Diq1AxSa.d.ts +0 -21
package/README.md
CHANGED
|
@@ -300,7 +300,7 @@ pageRouter.mount("#app", { hydrate: true, registry });
|
|
|
300
300
|
|
|
301
301
|
#### `.hydrate(registry, options?)` — browser only
|
|
302
302
|
|
|
303
|
-
Convenience method that combines `.prime()`, `ilha.mount()`, and `.mount()` into a single call. **This is the recommended client entry point.**
|
|
303
|
+
Convenience method that combines `.prime()`, `ilha.mount()`, and `.mount()` into a single call. **This is the recommended client entry point for SPA apps.**
|
|
304
304
|
|
|
305
305
|
```ts
|
|
306
306
|
pageRouter.hydrate(registry);
|
|
@@ -318,6 +318,23 @@ Returns an `unmount` function that tears down all listeners and hydrated islands
|
|
|
318
318
|
|
|
319
319
|
---
|
|
320
320
|
|
|
321
|
+
#### `.hydrateStatic(registry, options?)` — browser only
|
|
322
|
+
|
|
323
|
+
The lightest client entry point. Calls `prime()` then `ilha.mount()` — no route view is mounted, no navigation handler is installed, and no route graph is touched. Use this in `static` mode where each page is a self-contained pre-rendered HTML file.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
pageRouter.hydrateStatic(registry);
|
|
327
|
+
|
|
328
|
+
// With options:
|
|
329
|
+
pageRouter.hydrateStatic(registry, {
|
|
330
|
+
root: document.getElementById("app"), // defaults to document.body
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Internal `<a href>` links navigate via normal browser page loads. Only interactive islands in the current page are activated.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
321
338
|
#### `.attachLoader(pattern, loader)` — runtime
|
|
322
339
|
|
|
323
340
|
Attaches or replaces a loader on an already-registered route pattern. No-op if the pattern was never registered via `.route()`. Used by the `ilha:loaders` virtual module to wire server-only loaders onto the client-safe `pageRouter` at SSR time.
|
|
@@ -658,18 +675,21 @@ interface NavigateOptions {
|
|
|
658
675
|
interface MountOptions {
|
|
659
676
|
hydrate?: boolean;
|
|
660
677
|
registry?: Record<string, Island>;
|
|
678
|
+
interceptLinks?: boolean; // default: true
|
|
661
679
|
}
|
|
662
680
|
|
|
663
681
|
interface HydrateOptions {
|
|
664
682
|
root?: Element;
|
|
665
683
|
target?: string | Element;
|
|
684
|
+
interceptLinks?: boolean; // default: true
|
|
666
685
|
}
|
|
667
686
|
|
|
668
687
|
type HistoryMode = "history" | "hash";
|
|
669
|
-
type RouterMode = "spa" | "
|
|
688
|
+
type RouterMode = "spa" | "static";
|
|
670
689
|
|
|
671
690
|
interface RouterOptions {
|
|
672
|
-
mode?: RouterMode; // default: "spa"
|
|
691
|
+
mode?: RouterMode; // "spa" | "static", default: "spa"
|
|
692
|
+
interceptLinks?: boolean; // default: true — only meaningful in spa mode
|
|
673
693
|
}
|
|
674
694
|
|
|
675
695
|
// Helper — returns fn as-is with LayoutHandler type enforced
|
|
@@ -932,20 +952,14 @@ pageRouter.hydrate(registry);
|
|
|
932
952
|
pages({
|
|
933
953
|
dir: "src/pages", // pages directory (default: "src/pages")
|
|
934
954
|
generated: ".ilha/routes.ts", // generated file output (default: ".ilha/routes.ts")
|
|
935
|
-
mode: "spa", // "spa" | "
|
|
955
|
+
mode: "spa", // "spa" | "static" (default: "spa")
|
|
956
|
+
interceptLinks: true, // only meaningful in spa mode (default: true)
|
|
936
957
|
});
|
|
937
958
|
```
|
|
938
959
|
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
// vite.config.ts
|
|
943
|
-
import { pages } from "@ilha/router/vite";
|
|
944
|
-
|
|
945
|
-
export default defineConfig({
|
|
946
|
-
plugins: [pages({ mode: "mpa" })],
|
|
947
|
-
});
|
|
948
|
-
```
|
|
960
|
+
- **`mode: "spa"`** — full client route graph, SSR/hydration, and client-side navigation.
|
|
961
|
+
- **`mode: "spa", interceptLinks: false`** — full route graph and SSR/hydration, but internal links perform full document navigations.
|
|
962
|
+
- **`mode: "static"`** — island registry only; no route graph bundled. Each pre-rendered page hydrates its own islands via `pageRouter.hydrateStatic(registry)`.
|
|
949
963
|
|
|
950
964
|
The plugin regenerates the routes file only when content actually changes — avoiding unnecessary HMR invalidations. Structural changes (file add/remove, `+layout.ts`/`+error.ts` edits, or changes to loader exports) trigger full HMR reloads.
|
|
951
965
|
|
|
@@ -92,24 +92,43 @@ declare function defineLayout(layout: LayoutHandler): LayoutHandler;
|
|
|
92
92
|
interface NavigateOptions {
|
|
93
93
|
replace?: boolean;
|
|
94
94
|
}
|
|
95
|
-
type RouterMode = "spa" | "
|
|
95
|
+
type RouterMode = "spa" | "static";
|
|
96
96
|
interface RouterOptions {
|
|
97
97
|
/**
|
|
98
|
-
* Client navigation mode.
|
|
99
|
-
*
|
|
100
|
-
*
|
|
98
|
+
* Client navigation mode.
|
|
99
|
+
* - `spa` — full route graph, SSR/hydration, client-side navigation.
|
|
100
|
+
* - `static` — no route graph bundled; hydrate islands on the current
|
|
101
|
+
* pre-rendered page only.
|
|
101
102
|
* Default: `spa`.
|
|
102
103
|
*/
|
|
103
104
|
mode?: RouterMode;
|
|
105
|
+
/**
|
|
106
|
+
* When `true` (default), internal `<a>` clicks are intercepted and handled
|
|
107
|
+
* by the client router. Set to `false` for MPA-style behavior where links
|
|
108
|
+
* perform full document navigations.
|
|
109
|
+
* Only meaningful in `spa` mode; ignored in `static` mode.
|
|
110
|
+
* Default: `true`.
|
|
111
|
+
*/
|
|
112
|
+
interceptLinks?: boolean;
|
|
104
113
|
}
|
|
105
114
|
interface HydratableRenderOptions extends Partial<Omit<HydratableOptions, "name">> {}
|
|
106
115
|
interface HydrateOptions {
|
|
107
116
|
root?: Element;
|
|
108
117
|
target?: string | Element;
|
|
118
|
+
/**
|
|
119
|
+
* When `true` (default), internal `<a>` clicks are intercepted for
|
|
120
|
+
* client-side navigation. Set to `false` for MPA-style full-page navigations.
|
|
121
|
+
*/
|
|
122
|
+
interceptLinks?: boolean;
|
|
109
123
|
}
|
|
110
124
|
interface MountOptions {
|
|
111
125
|
hydrate?: boolean;
|
|
112
126
|
registry?: Record<string, Island<any, any>>;
|
|
127
|
+
/**
|
|
128
|
+
* When `true` (default), internal `<a>` clicks are intercepted for
|
|
129
|
+
* client-side navigation. Set to `false` for MPA-style full-page navigations.
|
|
130
|
+
*/
|
|
131
|
+
interceptLinks?: boolean;
|
|
113
132
|
}
|
|
114
133
|
/** Response envelope returned by `renderResponse` — lets the host app handle redirects. */
|
|
115
134
|
type RenderResponse = {
|
|
@@ -189,6 +208,14 @@ interface RouterBuilder {
|
|
|
189
208
|
* @returns Cleanup function
|
|
190
209
|
*/
|
|
191
210
|
hydrate(registry: Record<string, Island<any, any>>, options?: HydrateOptions): () => void;
|
|
211
|
+
/**
|
|
212
|
+
* Hydrate islands on the current pre-rendered page without mounting a route
|
|
213
|
+
* view or enabling client navigation. Intended for `static` mode: each page
|
|
214
|
+
* is a self-contained HTML file; only interactive islands need activation.
|
|
215
|
+
*/
|
|
216
|
+
hydrateStatic(registry: Record<string, Island<any, any>>, options?: {
|
|
217
|
+
root?: Element;
|
|
218
|
+
}): () => void;
|
|
192
219
|
}
|
|
193
220
|
/** Path of the loader endpoint served by the Vite plugin / production adapter. */
|
|
194
221
|
declare const LOADER_ENDPOINT = "/__ilha/loader";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as loader, B as useRoute, C as RouterView, D as enableLinkInterception, E as defineLayout, F as routeHash, G as setHistoryMode, H as wrapLayout, I as routeParams, L as routePath, M as prefetch, N as prime, O as error, P as redirect, R as routeSearch, S as RouterOptions, T as composeLoaders, U as HistoryMode, V as wrapError, W as getHistoryMode, _ as RouteRecord, a as InferLoader, b as RouterLink, c as LinkInterceptionOptions, d as LoaderError, f as MergeLoaders, g as RenderResponse, h as Redirect, i as HydrateOptions, j as navigate, k as isActive, l as Loader, m as NavigateOptions, n as ErrorHandler, o as LOADER_ENDPOINT, p as MountOptions, r as HydratableRenderOptions, s as LayoutHandler, t as AppError, u as LoaderContext, v as RouteSnapshot, w as _default, x as RouterMode, y as RouterBuilder, z as router } from "./index-
|
|
1
|
+
import { A as loader, B as useRoute, C as RouterView, D as enableLinkInterception, E as defineLayout, F as routeHash, G as setHistoryMode, H as wrapLayout, I as routeParams, L as routePath, M as prefetch, N as prime, O as error, P as redirect, R as routeSearch, S as RouterOptions, T as composeLoaders, U as HistoryMode, V as wrapError, W as getHistoryMode, _ as RouteRecord, a as InferLoader, b as RouterLink, c as LinkInterceptionOptions, d as LoaderError, f as MergeLoaders, g as RenderResponse, h as Redirect, i as HydrateOptions, j as navigate, k as isActive, l as Loader, m as NavigateOptions, n as ErrorHandler, o as LOADER_ENDPOINT, p as MountOptions, r as HydratableRenderOptions, s as LayoutHandler, t as AppError, u as LoaderContext, v as RouteSnapshot, w as _default, x as RouterMode, y as RouterBuilder, z as router } from "./index-DZA_1KrG.js";
|
|
2
2
|
export { AppError, ErrorHandler, HistoryMode, HydratableRenderOptions, HydrateOptions, InferLoader, LOADER_ENDPOINT, LayoutHandler, LinkInterceptionOptions, Loader, LoaderContext, LoaderError, MergeLoaders, MountOptions, NavigateOptions, Redirect, RenderResponse, RouteRecord, RouteSnapshot, RouterBuilder, RouterLink, RouterMode, RouterOptions, RouterView, composeLoaders, _default as default, defineLayout, enableLinkInterception, error, getHistoryMode, isActive, loader, navigate, prefetch, prime, redirect, routeHash, routeParams, routePath, routeSearch, router, setHistoryMode, useRoute, wrapError, wrapLayout };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as wrapError, E as setHistoryMode, S as useRoute, T as getHistoryMode, _ as routeParams, a as RouterView, b as router, c as enableLinkInterception, d as loader, f as navigate, g as routeHash, h as redirect, i as RouterLink, l as error, m as prime, n as LoaderError, o as composeLoaders, p as prefetch, r as Redirect, s as defineLayout, t as LOADER_ENDPOINT, u as isActive, v as routePath, w as wrapLayout, x as src_default, y as routeSearch } from "./src-
|
|
1
|
+
import { C as wrapError, E as setHistoryMode, S as useRoute, T as getHistoryMode, _ as routeParams, a as RouterView, b as router, c as enableLinkInterception, d as loader, f as navigate, g as routeHash, h as redirect, i as RouterLink, l as error, m as prime, n as LoaderError, o as composeLoaders, p as prefetch, r as Redirect, s as defineLayout, t as LOADER_ENDPOINT, u as isActive, v as routePath, w as wrapLayout, x as src_default, y as routeSearch } from "./src-BP38YTMC.js";
|
|
2
2
|
export { LOADER_ENDPOINT, LoaderError, Redirect, RouterLink, RouterView, composeLoaders, src_default as default, defineLayout, enableLinkInterception, error, getHistoryMode, isActive, loader, navigate, prefetch, prime, redirect, routeHash, routeParams, routePath, routeSearch, router, setHistoryMode, useRoute, wrapError, wrapLayout };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as _$unplugin from "unplugin";
|
|
2
|
+
|
|
3
|
+
//#region src/codegen.d.ts
|
|
4
|
+
type PagesMode = "spa" | "static";
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/plugin.d.ts
|
|
7
|
+
interface IlhaPagesOptions {
|
|
8
|
+
/** Directory containing page files. Default: `src/pages` */
|
|
9
|
+
dir?: string;
|
|
10
|
+
/** Output path for the generated routes + registry file. Default: `.ilha/routes.ts` */
|
|
11
|
+
generated?: string;
|
|
12
|
+
/**
|
|
13
|
+
* File-system router navigation mode.
|
|
14
|
+
* - `spa` — full client route graph with SSR/hydration and client navigation.
|
|
15
|
+
* - `static` — island registry only; no route graph bundled into the client.
|
|
16
|
+
* Default: `spa`.
|
|
17
|
+
*/
|
|
18
|
+
mode?: PagesMode;
|
|
19
|
+
/**
|
|
20
|
+
* When `false`, internal `<a>` clicks are not intercepted — browser performs
|
|
21
|
+
* full document navigations. Only meaningful in `spa` mode.
|
|
22
|
+
* Default: `true`.
|
|
23
|
+
*/
|
|
24
|
+
interceptLinks?: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare const ilhaPages: _$unplugin.UnpluginInstance<IlhaPagesOptions | undefined, boolean>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ilhaPages as n, IlhaPagesOptions as t };
|
|
@@ -140,13 +140,15 @@ function validateEntries(entries, pagesDir) {
|
|
|
140
140
|
}
|
|
141
141
|
async function generate(pagesDir, outFile, options = {}) {
|
|
142
142
|
const mode = options.mode ?? "spa";
|
|
143
|
+
const interceptLinks = options.interceptLinks;
|
|
144
|
+
const isStatic = mode === "static";
|
|
143
145
|
const entries = sortEntries(await scanPages(pagesDir));
|
|
144
146
|
validateEntries(entries, pagesDir);
|
|
145
147
|
const rel = (abs) => {
|
|
146
148
|
const r = toPosix(relative(dirname(outFile), abs));
|
|
147
149
|
return r.startsWith(".") ? r : `./${r}`;
|
|
148
150
|
};
|
|
149
|
-
const imports = [`import { router, wrapLayout, wrapError } from "@ilha/router";`, `import type { Island } from "ilha";`];
|
|
151
|
+
const imports = isStatic ? [`import type { Island } from "ilha";`] : [`import { router, wrapLayout, wrapError } from "@ilha/router";`, `import type { Island } from "ilha";`];
|
|
150
152
|
const wrappedIslandLines = [];
|
|
151
153
|
const registryLines = [];
|
|
152
154
|
const routeLines = [];
|
|
@@ -154,19 +156,26 @@ async function generate(pagesDir, outFile, options = {}) {
|
|
|
154
156
|
for (const [i, entry] of entries.entries()) {
|
|
155
157
|
const pageId = `_page${i}`;
|
|
156
158
|
imports.push(`import { default as ${pageId} } from ${JSON.stringify(clientImport(entry.file))};`);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
if (!isStatic) {
|
|
160
|
+
for (const [j, l] of entry.layouts.entries()) imports.push(`import { default as _layout${i}_${j} } from ${JSON.stringify(clientImport(l))};`);
|
|
161
|
+
for (const [j, e] of entry.errors.entries()) imports.push(`import { default as _error${i}_${j} } from ${JSON.stringify(clientImport(e))};`);
|
|
162
|
+
}
|
|
159
163
|
let expr = pageId;
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
if (!isStatic) {
|
|
165
|
+
for (let j = entry.errors.length - 1; j >= 0; j--) expr = `wrapError(_error${i}_${j}, ${expr})`;
|
|
166
|
+
for (let j = entry.layouts.length - 1; j >= 0; j--) expr = `wrapLayout(_layout${i}_${j}, ${expr})`;
|
|
167
|
+
}
|
|
162
168
|
const wrappedId = `_wrapped${i}`;
|
|
163
169
|
wrappedIslandLines.push(`const ${wrappedId} = ${expr};`);
|
|
164
170
|
registryLines.push(` ${JSON.stringify(entry.name)}: ${wrappedId}` + (i < entries.length - 1 ? "," : ""));
|
|
165
|
-
routeLines.push(` .route(${JSON.stringify(entry.pattern)}, ${wrappedId})` + (entry.hasLoader || entry.loaderLayouts.length > 0 ? `.markLoader(${JSON.stringify(entry.pattern)})` : ""));
|
|
171
|
+
if (!isStatic) routeLines.push(` .route(${JSON.stringify(entry.pattern)}, ${wrappedId})` + (entry.hasLoader || entry.loaderLayouts.length > 0 ? `.markLoader(${JSON.stringify(entry.pattern)})` : ""));
|
|
166
172
|
}
|
|
167
|
-
const code = [
|
|
173
|
+
const code = isStatic ? [
|
|
168
174
|
`// @generated by @ilha/router — do not edit`,
|
|
175
|
+
`// static mode: no route graph, no client navigation.`,
|
|
176
|
+
`// Import registry to hydrate islands; use pageRouter.hydrateStatic(registry).`,
|
|
169
177
|
``,
|
|
178
|
+
`import { router as _router } from "@ilha/router";`,
|
|
170
179
|
...imports,
|
|
171
180
|
``,
|
|
172
181
|
...wrappedIslandLines,
|
|
@@ -175,12 +184,28 @@ async function generate(pagesDir, outFile, options = {}) {
|
|
|
175
184
|
...registryLines,
|
|
176
185
|
`};`,
|
|
177
186
|
``,
|
|
178
|
-
`export const pageRouter =
|
|
187
|
+
`export const pageRouter = _router({ mode: "static" });`
|
|
188
|
+
].join("\n") : [
|
|
189
|
+
`// @generated by @ilha/router — do not edit`,
|
|
190
|
+
``,
|
|
191
|
+
...imports,
|
|
192
|
+
``,
|
|
193
|
+
...wrappedIslandLines,
|
|
194
|
+
``,
|
|
195
|
+
`export const registry: Record<string, Island<any, any>> = {`,
|
|
196
|
+
...registryLines,
|
|
197
|
+
`};`,
|
|
198
|
+
``,
|
|
199
|
+
`export const pageRouter = router(${interceptLinks === false ? `{ interceptLinks: false }` : ""})`,
|
|
179
200
|
...routeLines,
|
|
180
201
|
` ;`
|
|
181
202
|
].join("\n");
|
|
182
203
|
await mkdir(dirname(outFile), { recursive: true });
|
|
183
204
|
const routesChanged = await writeIfChanged(outFile, code);
|
|
205
|
+
if (isStatic) {
|
|
206
|
+
if (routesChanged) await generateTypes(outFile);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
184
209
|
const loadersFile = join(dirname(outFile), "loaders.ts");
|
|
185
210
|
const loadersChanged = await writeIfChanged(loadersFile, buildLoadersFile(entries, loadersFile, outFile));
|
|
186
211
|
if (routesChanged || loadersChanged) await generateTypes(outFile);
|
|
@@ -286,7 +311,10 @@ function createPagesPluginState(options) {
|
|
|
286
311
|
};
|
|
287
312
|
const regen = async () => {
|
|
288
313
|
try {
|
|
289
|
-
await generate(pagesDir, outFile, {
|
|
314
|
+
await generate(pagesDir, outFile, {
|
|
315
|
+
mode: options.mode,
|
|
316
|
+
interceptLinks: options.interceptLinks
|
|
317
|
+
});
|
|
290
318
|
} catch (e) {
|
|
291
319
|
console.error("[ilha:pages] codegen failed:", e);
|
|
292
320
|
}
|
package/dist/rolldown.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as wrapLayout, V as wrapError, n as ErrorHandler, s as LayoutHandler, t as AppError, v as RouteSnapshot } from "./index-
|
|
2
|
-
import { n as ilhaPages, t as IlhaPagesOptions } from "./plugin-
|
|
1
|
+
import { H as wrapLayout, V as wrapError, n as ErrorHandler, s as LayoutHandler, t as AppError, v as RouteSnapshot } from "./index-DZA_1KrG.js";
|
|
2
|
+
import { n as ilhaPages, t as IlhaPagesOptions } from "./plugin-BizQQLsn.js";
|
|
3
3
|
import * as _$unplugin from "unplugin";
|
|
4
4
|
|
|
5
5
|
//#region src/rolldown.d.ts
|
package/dist/rolldown.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as wrapError, w as wrapLayout } from "./src-
|
|
2
|
-
import { t as ilhaPages } from "./plugin-
|
|
1
|
+
import { C as wrapError, w as wrapLayout } from "./src-BP38YTMC.js";
|
|
2
|
+
import { t as ilhaPages } from "./plugin-C-TVH3XD.js";
|
|
3
3
|
//#region src/rolldown.ts
|
|
4
4
|
/** Rolldown plugin — use via `@ilha/router/rolldown`. */
|
|
5
5
|
function pages(options = {}) {
|
package/dist/rspack.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as wrapLayout, V as wrapError, n as ErrorHandler, s as LayoutHandler, t as AppError, v as RouteSnapshot } from "./index-
|
|
2
|
-
import { n as ilhaPages, t as IlhaPagesOptions } from "./plugin-
|
|
1
|
+
import { H as wrapLayout, V as wrapError, n as ErrorHandler, s as LayoutHandler, t as AppError, v as RouteSnapshot } from "./index-DZA_1KrG.js";
|
|
2
|
+
import { n as ilhaPages, t as IlhaPagesOptions } from "./plugin-BizQQLsn.js";
|
|
3
3
|
import * as _$unplugin from "unplugin";
|
|
4
4
|
|
|
5
5
|
//#region src/rspack.d.ts
|
package/dist/rspack.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as wrapError, w as wrapLayout } from "./src-
|
|
2
|
-
import { t as ilhaPages } from "./plugin-
|
|
1
|
+
import { C as wrapError, w as wrapLayout } from "./src-BP38YTMC.js";
|
|
2
|
+
import { t as ilhaPages } from "./plugin-C-TVH3XD.js";
|
|
3
3
|
//#region src/rspack.ts
|
|
4
4
|
/** Rspack plugin — use via `@ilha/router/rspack`. */
|
|
5
5
|
function pages(options = {}) {
|
|
@@ -579,6 +579,7 @@ async function executeLoader(loader, url, params, request, signal) {
|
|
|
579
579
|
}
|
|
580
580
|
function router(options = {}) {
|
|
581
581
|
const mode = options.mode ?? "spa";
|
|
582
|
+
const defaultInterceptLinks = options.interceptLinks !== false;
|
|
582
583
|
_records = [];
|
|
583
584
|
_rou3 = createRouter();
|
|
584
585
|
_islandToPattern = /* @__PURE__ */ new Map();
|
|
@@ -634,7 +635,14 @@ function router(options = {}) {
|
|
|
634
635
|
return _records.map((record) => ({ ...record }));
|
|
635
636
|
},
|
|
636
637
|
prime,
|
|
637
|
-
|
|
638
|
+
hydrateStatic(registry, options = {}) {
|
|
639
|
+
if (!isBrowser) return () => {};
|
|
640
|
+
const root = options.root ?? document.body;
|
|
641
|
+
prime();
|
|
642
|
+
const { unmount } = mount(registry, { root });
|
|
643
|
+
return unmount;
|
|
644
|
+
},
|
|
645
|
+
mount(target, { hydrate = false, registry, interceptLinks: mountInterceptLinks } = {}) {
|
|
638
646
|
if (!isBrowser) {
|
|
639
647
|
console.warn("[ilha-router] mount() called in a non-browser environment");
|
|
640
648
|
return () => {};
|
|
@@ -645,9 +653,13 @@ function router(options = {}) {
|
|
|
645
653
|
return () => {};
|
|
646
654
|
}
|
|
647
655
|
syncRouteFromLocation();
|
|
656
|
+
if (mode === "static") {
|
|
657
|
+
console.warn("[ilha-router] router.mount() called in static mode. Use router.hydrateStatic(registry) instead.");
|
|
658
|
+
return () => {};
|
|
659
|
+
}
|
|
648
660
|
const popHandler = () => syncRouteFromLocation();
|
|
649
661
|
_navChangeCleanup = getAdapter().onChange(popHandler);
|
|
650
|
-
_linkCleanup =
|
|
662
|
+
_linkCleanup = mountInterceptLinks ?? defaultInterceptLinks ? enableLinkInterception(document) : null;
|
|
651
663
|
let unmountView = null;
|
|
652
664
|
let navAbort = null;
|
|
653
665
|
if (hydrate) {
|
|
@@ -841,7 +853,8 @@ function router(options = {}) {
|
|
|
841
853
|
const { unmount } = mount(registry, { root });
|
|
842
854
|
const unmountRouter = this.mount(target, {
|
|
843
855
|
hydrate: true,
|
|
844
|
-
registry
|
|
856
|
+
registry,
|
|
857
|
+
interceptLinks: options.interceptLinks
|
|
845
858
|
});
|
|
846
859
|
return () => {
|
|
847
860
|
unmount();
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { H as wrapLayout, V as wrapError, n as ErrorHandler, s as LayoutHandler, t as AppError, v as RouteSnapshot } from "./index-
|
|
3
|
-
import { n as ilhaPages, t as IlhaPagesOptions } from "./plugin-
|
|
2
|
+
import { H as wrapLayout, V as wrapError, n as ErrorHandler, s as LayoutHandler, t as AppError, v as RouteSnapshot } from "./index-DZA_1KrG.js";
|
|
3
|
+
import { n as ilhaPages, t as IlhaPagesOptions } from "./plugin-BizQQLsn.js";
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
5
|
import * as http from "node:http";
|
|
6
6
|
import { Agent, ClientRequest, ClientRequestArgs, OutgoingHttpHeaders } from "node:http";
|
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as wrapError, w as wrapLayout } from "./src-
|
|
2
|
-
import { t as ilhaPages } from "./plugin-
|
|
1
|
+
import { C as wrapError, w as wrapLayout } from "./src-BP38YTMC.js";
|
|
2
|
+
import { t as ilhaPages } from "./plugin-C-TVH3XD.js";
|
|
3
3
|
//#region src/vite.ts
|
|
4
4
|
/** Vite plugin — use via `@ilha/router/vite`. */
|
|
5
5
|
function pages(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ilha/router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "A tiny SPA router for Ilha",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ryuz <ryuzer@proton.me>",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "bun test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"ilha": "0.7.
|
|
41
|
+
"ilha": "0.7.1",
|
|
42
42
|
"rou3": "0.8.1",
|
|
43
43
|
"unplugin": "3.0.0"
|
|
44
44
|
},
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as _$unplugin from "unplugin";
|
|
2
|
-
|
|
3
|
-
//#region src/codegen.d.ts
|
|
4
|
-
type PagesMode = "spa" | "mpa";
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/plugin.d.ts
|
|
7
|
-
interface IlhaPagesOptions {
|
|
8
|
-
/** Directory containing page files. Default: `src/pages` */
|
|
9
|
-
dir?: string;
|
|
10
|
-
/** Output path for the generated routes + registry file. Default: `.ilha/routes.ts` */
|
|
11
|
-
generated?: string;
|
|
12
|
-
/**
|
|
13
|
-
* File-system router navigation mode. `spa` intercepts in-app links and
|
|
14
|
-
* renders routes client-side; `mpa` leaves links to the browser for full
|
|
15
|
-
* document navigations. Default: `spa`.
|
|
16
|
-
*/
|
|
17
|
-
mode?: PagesMode;
|
|
18
|
-
}
|
|
19
|
-
declare const ilhaPages: _$unplugin.UnpluginInstance<IlhaPagesOptions | undefined, boolean>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { ilhaPages as n, IlhaPagesOptions as t };
|