@qwik.dev/router 2.0.0-beta.5 → 2.0.0-beta.7
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/adapters/static/vite.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.cjs +1 -0
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +1 -0
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/shared/vite/index.cjs +88 -128
- package/lib/adapters/shared/vite/index.d.ts +9 -15
- package/lib/adapters/shared/vite/index.mjs +88 -124
- package/lib/adapters/{static → ssg}/vite/index.cjs +95 -124
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/{static → ssg}/vite/index.mjs +93 -123
- package/lib/adapters/vercel-edge/vite/index.d.ts +2 -2
- package/lib/index.d.ts +161 -48
- package/lib/index.qwik.cjs +86 -23
- package/lib/index.qwik.mjs +88 -25
- package/lib/middleware/aws-lambda/index.d.ts +3 -2
- package/lib/middleware/aws-lambda/index.mjs +2 -4
- package/lib/middleware/azure-swa/index.mjs +6 -6
- package/lib/middleware/bun/index.mjs +4 -6
- package/lib/middleware/cloudflare-pages/index.mjs +4 -6
- package/lib/middleware/deno/index.mjs +8 -7
- package/lib/middleware/firebase/index.mjs +1 -3
- package/lib/middleware/netlify-edge/index.mjs +7 -6
- package/lib/middleware/node/index.cjs +4 -8
- package/lib/middleware/node/index.mjs +7 -7
- package/lib/middleware/request-handler/index.cjs +331 -268
- package/lib/middleware/request-handler/index.d.ts +56 -49
- package/lib/middleware/request-handler/index.mjs +335 -264
- package/lib/middleware/vercel-edge/index.mjs +7 -6
- package/lib/modules.d.ts +4 -12
- package/lib/{static → ssg}/deno.mjs +1 -1
- package/lib/{static → ssg}/index.cjs +1 -1
- package/lib/{static → ssg}/index.d.ts +17 -17
- package/lib/{static → ssg}/index.mjs +1 -1
- package/lib/{static → ssg}/node.cjs +16 -16
- package/lib/{static → ssg}/node.mjs +15 -15
- package/lib/vite/index.cjs +10260 -10437
- package/lib/vite/index.mjs +8220 -8387
- package/modules.d.ts +4 -12
- package/package.json +19 -8
- package/ssg.d.ts +2 -0
- package/static.d.ts +1 -1
- package/lib/adapters/static/vite/index.d.ts +0 -10
- package/middleware/request-handler/generated/not-found-paths.ts +0 -7
- package/middleware/request-handler/generated/static-paths.ts +0 -35
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
2
|
-
import fs2 from "node:fs";
|
|
3
2
|
import { basename, dirname, join as join2, resolve } from "node:path";
|
|
4
3
|
|
|
5
4
|
// packages/qwik-router/src/adapters/shared/vite/post-build.ts
|
|
6
5
|
import { getErrorHtml } from "@qwik.dev/router/middleware/request-handler";
|
|
7
6
|
import fs from "node:fs";
|
|
8
7
|
import { join } from "node:path";
|
|
9
|
-
async function postBuild(clientOutDir, pathName, userStaticPaths,
|
|
8
|
+
async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
|
|
10
9
|
if (pathName && !pathName.endsWith("/")) {
|
|
11
10
|
pathName += "/";
|
|
12
11
|
}
|
|
13
|
-
const ignorePathnames = /* @__PURE__ */ new Set([
|
|
12
|
+
const ignorePathnames = /* @__PURE__ */ new Set([
|
|
13
|
+
pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
|
|
14
|
+
pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
|
|
15
|
+
]);
|
|
14
16
|
const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
|
|
15
17
|
const notFounds = [];
|
|
16
18
|
const loadItem = async (fsDir, fsName, pathname) => {
|
|
@@ -44,12 +46,9 @@ async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanS
|
|
|
44
46
|
if (fs.existsSync(clientOutDir)) {
|
|
45
47
|
await loadDir(clientOutDir, pathName);
|
|
46
48
|
}
|
|
47
|
-
const notFoundPathsCode =
|
|
48
|
-
const staticPathsCode =
|
|
49
|
-
|
|
50
|
-
notFoundPathsCode,
|
|
51
|
-
staticPathsCode
|
|
52
|
-
};
|
|
49
|
+
const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
|
|
50
|
+
const staticPathsCode = createStaticPathsCode(staticPaths);
|
|
51
|
+
await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
|
|
53
52
|
}
|
|
54
53
|
function normalizeTrailingSlash(pathname) {
|
|
55
54
|
if (!pathname.endsWith("/")) {
|
|
@@ -57,7 +56,7 @@ function normalizeTrailingSlash(pathname) {
|
|
|
57
56
|
}
|
|
58
57
|
return pathname;
|
|
59
58
|
}
|
|
60
|
-
function
|
|
59
|
+
function createNotFoundPathsCode(basePathname, notFounds) {
|
|
61
60
|
notFounds.sort((a, b) => {
|
|
62
61
|
if (a[0].length > b[0].length) {
|
|
63
62
|
return -1;
|
|
@@ -77,64 +76,43 @@ function createNotFoundPathsModule(basePathname, notFounds, format) {
|
|
|
77
76
|
const html = getErrorHtml(404, "Resource Not Found");
|
|
78
77
|
notFounds.push([basePathname, html]);
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
c.push(`const notFounds = ${JSON.stringify(notFounds, null, 2)};`);
|
|
82
|
-
c.push(`function getNotFound(p) {`);
|
|
83
|
-
c.push(` for (const r of notFounds) {`);
|
|
84
|
-
c.push(` if (p.startsWith(r[0])) {`);
|
|
85
|
-
c.push(` return r[1];`);
|
|
86
|
-
c.push(` }`);
|
|
87
|
-
c.push(` }`);
|
|
88
|
-
c.push(` return "Resource Not Found";`);
|
|
89
|
-
c.push(`}`);
|
|
90
|
-
if (format === "cjs") {
|
|
91
|
-
c.push("exports.getNotFound = getNotFound;");
|
|
92
|
-
} else {
|
|
93
|
-
c.push("export { getNotFound };");
|
|
94
|
-
}
|
|
95
|
-
return c.join("\n");
|
|
79
|
+
return JSON.stringify(notFounds, null, 2).slice(1, -1);
|
|
96
80
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
const baseBuildPath = basePathname + "build/";
|
|
100
|
-
const c = [];
|
|
101
|
-
c.push(
|
|
102
|
-
`const staticPaths = new Set(${JSON.stringify(
|
|
103
|
-
Array.from(new Set(staticPaths)).sort()
|
|
104
|
-
)});`
|
|
105
|
-
);
|
|
106
|
-
c.push(`function isStaticPath(method, url) {`);
|
|
107
|
-
c.push(` if (method.toUpperCase() !== 'GET') {`);
|
|
108
|
-
c.push(` return false;`);
|
|
109
|
-
c.push(` }`);
|
|
110
|
-
c.push(` const p = url.pathname;`);
|
|
111
|
-
c.push(` if (p.startsWith(${JSON.stringify(baseBuildPath)})) {`);
|
|
112
|
-
c.push(` return true;`);
|
|
113
|
-
c.push(` }`);
|
|
114
|
-
c.push(` if (p.startsWith(${JSON.stringify(assetsPath)})) {`);
|
|
115
|
-
c.push(` return true;`);
|
|
116
|
-
c.push(` }`);
|
|
117
|
-
c.push(` if (staticPaths.has(p)) {`);
|
|
118
|
-
c.push(` return true;`);
|
|
119
|
-
c.push(` }`);
|
|
120
|
-
c.push(` if (p.endsWith('/q-data.json')) {`);
|
|
121
|
-
c.push(` const pWithoutQdata = p.replace(/\\/q-data.json$/, '');`);
|
|
122
|
-
c.push(` if (staticPaths.has(pWithoutQdata + '/')) {`);
|
|
123
|
-
c.push(` return true;`);
|
|
124
|
-
c.push(` }`);
|
|
125
|
-
c.push(` if (staticPaths.has(pWithoutQdata)) {`);
|
|
126
|
-
c.push(` return true;`);
|
|
127
|
-
c.push(` }`);
|
|
128
|
-
c.push(` }`);
|
|
129
|
-
c.push(` return false;`);
|
|
130
|
-
c.push(`}`);
|
|
131
|
-
if (format === "cjs") {
|
|
132
|
-
c.push("exports.isStaticPath = isStaticPath;");
|
|
133
|
-
} else {
|
|
134
|
-
c.push("export { isStaticPath };");
|
|
135
|
-
}
|
|
136
|
-
return c.join("\n");
|
|
81
|
+
function createStaticPathsCode(staticPaths) {
|
|
82
|
+
return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
|
|
137
83
|
}
|
|
84
|
+
var injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
|
|
85
|
+
const promises = /* @__PURE__ */ new Set();
|
|
86
|
+
const doReplace = async (path) => {
|
|
87
|
+
const code = await fs.promises.readFile(path, "utf-8");
|
|
88
|
+
let replaced = false;
|
|
89
|
+
const newCode = code.replace(
|
|
90
|
+
/(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g,
|
|
91
|
+
(_, _quote, type) => {
|
|
92
|
+
replaced = true;
|
|
93
|
+
return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
if (replaced) {
|
|
97
|
+
await fs.promises.writeFile(path, newCode);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const walk = async (dir) => {
|
|
101
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
if (entry.isDirectory()) {
|
|
104
|
+
await walk(join(dir, entry.name));
|
|
105
|
+
} else if (entry.name.endsWith("js")) {
|
|
106
|
+
const p = doReplace(join(dir, entry.name)).finally(() => {
|
|
107
|
+
promises.delete(p);
|
|
108
|
+
});
|
|
109
|
+
promises.add(p);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
await walk(outDir);
|
|
114
|
+
await Promise.all(promises);
|
|
115
|
+
};
|
|
138
116
|
|
|
139
117
|
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
140
118
|
function viteAdapter(opts) {
|
|
@@ -144,10 +122,9 @@ function viteAdapter(opts) {
|
|
|
144
122
|
let renderModulePath = null;
|
|
145
123
|
let qwikRouterConfigModulePath = null;
|
|
146
124
|
let isSsrBuild = false;
|
|
147
|
-
let format = "esm";
|
|
148
125
|
const outputEntries = [];
|
|
149
126
|
const plugin = {
|
|
150
|
-
name: `vite-plugin-qwik-router-${opts.name}`,
|
|
127
|
+
name: `vite-plugin-qwik-router-ssg-${opts.name}`,
|
|
151
128
|
enforce: "post",
|
|
152
129
|
apply: "build",
|
|
153
130
|
config(config) {
|
|
@@ -161,7 +138,7 @@ function viteAdapter(opts) {
|
|
|
161
138
|
return config;
|
|
162
139
|
},
|
|
163
140
|
configResolved(config) {
|
|
164
|
-
var _a, _b, _c
|
|
141
|
+
var _a, _b, _c;
|
|
165
142
|
isSsrBuild = !!config.build.ssr;
|
|
166
143
|
if (isSsrBuild) {
|
|
167
144
|
qwikRouterPlugin = config.plugins.find(
|
|
@@ -187,9 +164,21 @@ function viteAdapter(opts) {
|
|
|
187
164
|
`"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
|
|
188
165
|
);
|
|
189
166
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
buildStart() {
|
|
170
|
+
if (isSsrBuild && opts.ssg !== null) {
|
|
171
|
+
const { srcDir } = qwikVitePlugin.api.getOptions();
|
|
172
|
+
this.emitFile({
|
|
173
|
+
id: "@qwik-router-config",
|
|
174
|
+
type: "chunk",
|
|
175
|
+
fileName: "@qwik-router-config.js"
|
|
176
|
+
});
|
|
177
|
+
this.emitFile({
|
|
178
|
+
id: `${srcDir}/entry.ssr`,
|
|
179
|
+
type: "chunk",
|
|
180
|
+
fileName: "entry.ssr.js"
|
|
181
|
+
});
|
|
193
182
|
}
|
|
194
183
|
},
|
|
195
184
|
generateBundle(_, bundles) {
|
|
@@ -206,23 +195,13 @@ function viteAdapter(opts) {
|
|
|
206
195
|
}
|
|
207
196
|
}
|
|
208
197
|
}
|
|
209
|
-
if (!renderModulePath) {
|
|
210
|
-
throw new Error(
|
|
211
|
-
'Unable to find "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?'
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
if (!qwikRouterConfigModulePath) {
|
|
215
|
-
throw new Error(
|
|
216
|
-
'Unable to find "@qwik-router-config" entry point. Did you forget to add it to "build.rollupOptions.input"?'
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
198
|
}
|
|
220
199
|
},
|
|
221
200
|
closeBundle: {
|
|
222
201
|
sequential: true,
|
|
223
202
|
async handler() {
|
|
224
203
|
var _a;
|
|
225
|
-
if (isSsrBuild &&
|
|
204
|
+
if (isSsrBuild && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
|
|
226
205
|
const staticPaths = opts.staticPaths || [];
|
|
227
206
|
const routes = qwikRouterPlugin.api.getRoutes();
|
|
228
207
|
const basePathname = qwikRouterPlugin.api.getBasePathname();
|
|
@@ -230,7 +209,7 @@ function viteAdapter(opts) {
|
|
|
230
209
|
const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
|
|
231
210
|
const assetsDir = qwikVitePlugin.api.getAssetsDir();
|
|
232
211
|
const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
|
|
233
|
-
if (renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
|
|
212
|
+
if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
|
|
234
213
|
let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
|
|
235
214
|
if (!ssgOrigin) {
|
|
236
215
|
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
@@ -243,13 +222,13 @@ function viteAdapter(opts) {
|
|
|
243
222
|
}
|
|
244
223
|
try {
|
|
245
224
|
ssgOrigin = new URL(ssgOrigin).origin;
|
|
246
|
-
} catch
|
|
225
|
+
} catch {
|
|
247
226
|
this.warn(
|
|
248
227
|
`Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
|
|
249
228
|
);
|
|
250
229
|
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
251
230
|
}
|
|
252
|
-
const staticGenerate = await import("../../../
|
|
231
|
+
const staticGenerate = await import("../../../ssg/index.mjs");
|
|
253
232
|
const generateOpts = {
|
|
254
233
|
maxWorkers: opts.maxWorkers,
|
|
255
234
|
basePathname,
|
|
@@ -269,56 +248,45 @@ function viteAdapter(opts) {
|
|
|
269
248
|
this.error(err);
|
|
270
249
|
}
|
|
271
250
|
staticPaths.push(...staticGenerateResult.staticPaths);
|
|
272
|
-
|
|
251
|
+
}
|
|
252
|
+
await postBuild(
|
|
253
|
+
clientPublicOutDir,
|
|
254
|
+
serverOutDir,
|
|
255
|
+
assetsDir ? join2(basePathname, assetsDir) : basePathname,
|
|
256
|
+
staticPaths,
|
|
257
|
+
!!opts.cleanStaticGenerated
|
|
258
|
+
);
|
|
259
|
+
if (typeof opts.generate === "function") {
|
|
260
|
+
await opts.generate({
|
|
261
|
+
outputEntries,
|
|
262
|
+
serverOutDir,
|
|
263
|
+
clientOutDir,
|
|
273
264
|
clientPublicOutDir,
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
notFoundPathsCode
|
|
284
|
-
)
|
|
285
|
-
]);
|
|
286
|
-
if (typeof opts.generate === "function") {
|
|
287
|
-
await opts.generate({
|
|
288
|
-
outputEntries,
|
|
289
|
-
serverOutDir,
|
|
290
|
-
clientOutDir,
|
|
291
|
-
clientPublicOutDir,
|
|
292
|
-
basePathname,
|
|
293
|
-
routes,
|
|
294
|
-
assetsDir,
|
|
295
|
-
warn: (message) => this.warn(message),
|
|
296
|
-
error: (message) => this.error(message)
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
this.warn(
|
|
300
|
-
`
|
|
265
|
+
basePathname,
|
|
266
|
+
routes,
|
|
267
|
+
assetsDir,
|
|
268
|
+
warn: (message) => this.warn(message),
|
|
269
|
+
error: (message) => this.error(message)
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
this.warn(
|
|
273
|
+
`
|
|
301
274
|
==============================================
|
|
302
275
|
Note: Make sure that you are serving the built files with proper cache headers.
|
|
303
276
|
See https://qwik.dev/docs/deployments/#cache-headers for more information.
|
|
304
277
|
==============================================`
|
|
305
|
-
|
|
306
|
-
}
|
|
278
|
+
);
|
|
307
279
|
}
|
|
308
280
|
}
|
|
309
281
|
}
|
|
310
282
|
};
|
|
311
283
|
return plugin;
|
|
312
284
|
}
|
|
313
|
-
var STATIC_PATHS_ID = "@qwik-router-static-paths";
|
|
314
|
-
var RESOLVED_STATIC_PATHS_ID = `${STATIC_PATHS_ID}.js`;
|
|
315
|
-
var NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths";
|
|
316
|
-
var RESOLVED_NOT_FOUND_PATHS_ID = `${NOT_FOUND_PATHS_ID}.js`;
|
|
317
285
|
|
|
318
|
-
// packages/qwik-router/src/adapters/
|
|
319
|
-
function
|
|
286
|
+
// packages/qwik-router/src/adapters/ssg/vite/index.ts
|
|
287
|
+
function ssgAdapter(opts) {
|
|
320
288
|
return viteAdapter({
|
|
321
|
-
name: "static-
|
|
289
|
+
name: "static-site-generation",
|
|
322
290
|
origin: opts.origin,
|
|
323
291
|
ssg: {
|
|
324
292
|
include: ["/*"],
|
|
@@ -326,6 +294,8 @@ function staticAdapter(opts) {
|
|
|
326
294
|
}
|
|
327
295
|
});
|
|
328
296
|
}
|
|
297
|
+
var staticAdapter = ssgAdapter;
|
|
329
298
|
export {
|
|
299
|
+
ssgAdapter,
|
|
330
300
|
staticAdapter
|
|
331
301
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServerAdapterOptions } from '../../shared/vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SsgRenderOptions } from 'packages/qwik-router/src/ssg';
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export { SsgRenderOptions }
|
|
5
5
|
|
|
6
6
|
/** @public */
|
|
7
7
|
export declare function vercelEdgeAdapter(opts?: VercelEdgeAdapterOptions): any;
|
package/lib/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { QRLEventHandlerMulti } from '@qwik.dev/core';
|
|
|
12
12
|
import { QwikIntrinsicElements } from '@qwik.dev/core';
|
|
13
13
|
import { QwikJSX } from '@qwik.dev/core';
|
|
14
14
|
import type { ReadonlySignal } from '@qwik.dev/core';
|
|
15
|
+
import { Render } from '@qwik.dev/core/server';
|
|
16
|
+
import { RenderOptions } from '@qwik.dev/core/server';
|
|
15
17
|
import { RequestEvent } from '@qwik.dev/router/middleware/request-handler';
|
|
16
18
|
import { RequestEventAction } from '@qwik.dev/router/middleware/request-handler';
|
|
17
19
|
import { RequestEventBase } from '@qwik.dev/router/middleware/request-handler';
|
|
@@ -189,6 +191,38 @@ export { CookieOptions }
|
|
|
189
191
|
|
|
190
192
|
export { CookieValue }
|
|
191
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Creates the `render()` function that is required by `createQwikRouter()`. It requires a function
|
|
196
|
+
* that returns the `jsx` and `options` for the renderer.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
*
|
|
200
|
+
* ```tsx
|
|
201
|
+
* const renderer = createRenderer((opts) => {
|
|
202
|
+
* if (opts.requestHeaders['x-hello'] === 'world') {
|
|
203
|
+
* return { jsx: <Hello />, options: opts };
|
|
204
|
+
* }
|
|
205
|
+
* return { jsx: <Root />, options: {
|
|
206
|
+
* ...opts,
|
|
207
|
+
* serverData: {
|
|
208
|
+
* ...opts.serverData,
|
|
209
|
+
* documentHead: {
|
|
210
|
+
* meta: [
|
|
211
|
+
* { name: 'renderedAt', content: new Date().toISOString() },
|
|
212
|
+
* ],
|
|
213
|
+
* },
|
|
214
|
+
* },
|
|
215
|
+
* } };
|
|
216
|
+
* });
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
export declare const createRenderer: (getOptions: (options: RendererOptions) => {
|
|
222
|
+
jsx: JSXOutput_2;
|
|
223
|
+
options: RendererOutputOptions;
|
|
224
|
+
}) => Render;
|
|
225
|
+
|
|
192
226
|
/** @public */
|
|
193
227
|
export declare type DataValidator<T extends Record<string, any> = {}> = {
|
|
194
228
|
validate(ev: RequestEvent, data: unknown): Promise<ValidatorReturn<T>>;
|
|
@@ -214,14 +248,35 @@ export declare interface DocumentHeadProps extends RouteLocation {
|
|
|
214
248
|
readonly resolveValue: ResolveSyncValue;
|
|
215
249
|
}
|
|
216
250
|
|
|
251
|
+
/**
|
|
252
|
+
* This renders all the tags collected from `head`.
|
|
253
|
+
*
|
|
254
|
+
* You can partially override the head, for example if you want to change the title:
|
|
255
|
+
*
|
|
256
|
+
* ```tsx
|
|
257
|
+
* import { DocumentHeadTags, useDocumentHead } from '@qwik.dev/router';
|
|
258
|
+
*
|
|
259
|
+
* export default component$(() => {
|
|
260
|
+
* const head = useDocumentHead();
|
|
261
|
+
* return <DocumentHeadTags title={`${head.title} - My App`} />;
|
|
262
|
+
* });
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* You don't have to use this component, you can also do it yourself for full control. Just copy the
|
|
266
|
+
* code from this component and modify it to your needs.
|
|
267
|
+
*
|
|
268
|
+
* Note that this component normally only runs once, during SSR. You can use Signals in your
|
|
269
|
+
* `src/root.tsx` to make runtime changes to `<head>` if needed.
|
|
270
|
+
*
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
export declare const DocumentHeadTags: Component<DocumentHeadValue<Record<string, unknown>>>;
|
|
274
|
+
|
|
217
275
|
/** @public */
|
|
218
276
|
export declare interface DocumentHeadValue<FrontMatter extends Record<string, any> = Record<string, unknown>> {
|
|
219
277
|
/** Sets `document.title`. */
|
|
220
278
|
readonly title?: string;
|
|
221
|
-
/**
|
|
222
|
-
* Used to manually set meta tags in the head. Additionally, the `data` property could be used to
|
|
223
|
-
* set arbitrary data which the `<head>` component could later use to generate `<meta>` tags.
|
|
224
|
-
*/
|
|
279
|
+
/** Used to manually set meta tags in the head. */
|
|
225
280
|
readonly meta?: readonly DocumentMeta[];
|
|
226
281
|
/** Used to manually append `<link>` elements to the `<head>`. */
|
|
227
282
|
readonly links?: readonly DocumentLink[];
|
|
@@ -238,53 +293,59 @@ export declare interface DocumentHeadValue<FrontMatter extends Record<string, an
|
|
|
238
293
|
}
|
|
239
294
|
|
|
240
295
|
/** @public */
|
|
241
|
-
export declare
|
|
242
|
-
as?: string;
|
|
243
|
-
crossorigin?: string;
|
|
244
|
-
disabled?: boolean;
|
|
245
|
-
href?: string;
|
|
246
|
-
hreflang?: string;
|
|
247
|
-
id?: string;
|
|
248
|
-
imagesizes?: string;
|
|
249
|
-
imagesrcset?: string;
|
|
250
|
-
integrity?: string;
|
|
251
|
-
media?: string;
|
|
252
|
-
prefetch?: string;
|
|
253
|
-
referrerpolicy?: string;
|
|
254
|
-
rel?: string;
|
|
255
|
-
sizes?: string;
|
|
256
|
-
title?: string;
|
|
257
|
-
type?: string;
|
|
258
|
-
key?: string;
|
|
259
|
-
}
|
|
296
|
+
export declare type DocumentLink = QwikIntrinsicElements['link'];
|
|
260
297
|
|
|
261
298
|
/** @public */
|
|
262
|
-
export declare
|
|
263
|
-
readonly content?: string;
|
|
264
|
-
readonly httpEquiv?: string;
|
|
265
|
-
readonly name?: string;
|
|
266
|
-
readonly property?: string;
|
|
267
|
-
readonly key?: string;
|
|
268
|
-
readonly itemprop?: string;
|
|
269
|
-
readonly media?: string;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/** @beta */
|
|
273
|
-
export declare interface DocumentScript {
|
|
274
|
-
readonly script?: string;
|
|
275
|
-
readonly props?: Readonly<QwikIntrinsicElements['script']>;
|
|
276
|
-
readonly key?: string;
|
|
277
|
-
}
|
|
299
|
+
export declare type DocumentMeta = QwikIntrinsicElements['meta'];
|
|
278
300
|
|
|
279
301
|
/** @public */
|
|
280
|
-
export declare
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
302
|
+
export declare type DocumentScript = ((Omit<QwikIntrinsicElements['script'], 'dangerouslySetInnerHTML'> & {
|
|
303
|
+
props?: never;
|
|
304
|
+
}) | {
|
|
305
|
+
key?: string;
|
|
306
|
+
/**
|
|
307
|
+
* The props of the script element. @deprecated Prefer setting the properties directly instead
|
|
308
|
+
* of using this property.
|
|
309
|
+
*/
|
|
310
|
+
props: Readonly<QwikIntrinsicElements['script']>;
|
|
311
|
+
}) & ({
|
|
312
|
+
/** The inline script content. */
|
|
313
|
+
script?: string;
|
|
314
|
+
dangerouslySetInnerHTML?: never;
|
|
315
|
+
} | {
|
|
316
|
+
dangerouslySetInnerHTML?: string;
|
|
317
|
+
script?: never;
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
/** @public */
|
|
321
|
+
export declare type DocumentStyle = Readonly<((Omit<QwikIntrinsicElements['style'], 'dangerouslySetInnerHTML'> & {
|
|
322
|
+
props?: never;
|
|
323
|
+
}) | {
|
|
324
|
+
key?: string;
|
|
325
|
+
/**
|
|
326
|
+
* The props of the style element. @deprecated Prefer setting the properties directly
|
|
327
|
+
* instead of using this property.
|
|
328
|
+
*/
|
|
329
|
+
props: Readonly<QwikIntrinsicElements['style']>;
|
|
330
|
+
}) & ({
|
|
331
|
+
/** The inline style content. */
|
|
332
|
+
style?: string;
|
|
333
|
+
dangerouslySetInnerHTML?: never;
|
|
334
|
+
} | {
|
|
335
|
+
dangerouslySetInnerHTML?: string;
|
|
336
|
+
style?: never;
|
|
337
|
+
})>;
|
|
285
338
|
|
|
286
339
|
declare type EndpointModuleLoader = () => Promise<RouteModule>;
|
|
287
340
|
|
|
341
|
+
declare interface EndpointResponse {
|
|
342
|
+
status: number;
|
|
343
|
+
loaders: Record<string, unknown>;
|
|
344
|
+
loadersSerializationStrategy: Map<string, SerializationStrategy>;
|
|
345
|
+
formData?: FormData;
|
|
346
|
+
action?: string;
|
|
347
|
+
}
|
|
348
|
+
|
|
288
349
|
/** @public */
|
|
289
350
|
export declare const ErrorBoundary: Component<ErrorBoundaryProps>;
|
|
290
351
|
|
|
@@ -427,6 +488,14 @@ export declare interface LinkProps extends AnchorAttributes {
|
|
|
427
488
|
scroll?: boolean;
|
|
428
489
|
}
|
|
429
490
|
|
|
491
|
+
declare type LoadedRoute = [
|
|
492
|
+
routeName: string,
|
|
493
|
+
params: PathParams,
|
|
494
|
+
mods: (RouteModule | ContentModule)[],
|
|
495
|
+
menu: ContentMenu | undefined,
|
|
496
|
+
routeBundleNames: string[] | undefined
|
|
497
|
+
];
|
|
498
|
+
|
|
430
499
|
/** @public */
|
|
431
500
|
declare type Loader_2<RETURN> = {
|
|
432
501
|
/**
|
|
@@ -510,6 +579,9 @@ declare type Prettify<T> = {} & {
|
|
|
510
579
|
*/
|
|
511
580
|
export declare type PreventNavigateCallback = (url?: number | URL) => ValueOrPromise<boolean>;
|
|
512
581
|
|
|
582
|
+
/** @public */
|
|
583
|
+
export declare const Q_ROUTE = "q:route";
|
|
584
|
+
|
|
513
585
|
/**
|
|
514
586
|
* @deprecated Use `QWIK_ROUTER_SCROLLER` instead (will be removed in V3)
|
|
515
587
|
* @public
|
|
@@ -526,7 +598,7 @@ export declare const QWIK_ROUTER_SCROLLER = "_qRouterScroller";
|
|
|
526
598
|
export declare type QwikCityMockProps = QwikRouterMockProps;
|
|
527
599
|
|
|
528
600
|
/**
|
|
529
|
-
* @deprecated Use `
|
|
601
|
+
* @deprecated Use `useQwikMockRouter()` instead. Will be removed in V3
|
|
530
602
|
* @public
|
|
531
603
|
*/
|
|
532
604
|
export declare const QwikCityMockProvider: Component<QwikRouterMockProps>;
|
|
@@ -538,13 +610,13 @@ export declare const QwikCityMockProvider: Component<QwikRouterMockProps>;
|
|
|
538
610
|
export declare type QwikCityPlan = QwikRouterConfig;
|
|
539
611
|
|
|
540
612
|
/**
|
|
541
|
-
* @deprecated Use `QwikRouterProps` instead.
|
|
613
|
+
* @deprecated Use `QwikRouterProps` instead. Will be removed in v3.
|
|
542
614
|
* @public
|
|
543
615
|
*/
|
|
544
616
|
export declare type QwikCityProps = QwikRouterProps;
|
|
545
617
|
|
|
546
618
|
/**
|
|
547
|
-
* @deprecated Use `
|
|
619
|
+
* @deprecated Use `useQwikRouter()` instead. Will be removed in v3.
|
|
548
620
|
* @public
|
|
549
621
|
*/
|
|
550
622
|
export declare const QwikCityProvider: Component<QwikRouterProps>;
|
|
@@ -559,6 +631,15 @@ export declare interface QwikRouterConfig {
|
|
|
559
631
|
readonly cacheModules?: boolean;
|
|
560
632
|
}
|
|
561
633
|
|
|
634
|
+
/** @public */
|
|
635
|
+
export declare interface QwikRouterEnvData {
|
|
636
|
+
routeName: string;
|
|
637
|
+
ev: RequestEvent;
|
|
638
|
+
params: PathParams;
|
|
639
|
+
response: EndpointResponse;
|
|
640
|
+
loadedRoute: LoadedRoute | null;
|
|
641
|
+
}
|
|
642
|
+
|
|
562
643
|
/** @public */
|
|
563
644
|
export declare interface QwikRouterMockProps {
|
|
564
645
|
url?: string;
|
|
@@ -583,7 +664,7 @@ export declare interface QwikRouterProps {
|
|
|
583
664
|
viewTransition?: boolean;
|
|
584
665
|
}
|
|
585
666
|
|
|
586
|
-
/** @public */
|
|
667
|
+
/** @public This is a wrapper around the `useQwikRouter()` hook. We recommend using the hook instead of this component. */
|
|
587
668
|
export declare const QwikRouterProvider: Component<QwikRouterProps>;
|
|
588
669
|
|
|
589
670
|
/** @public */
|
|
@@ -591,6 +672,18 @@ declare interface ReadonlySignal_2<T = unknown> {
|
|
|
591
672
|
readonly value: T;
|
|
592
673
|
}
|
|
593
674
|
|
|
675
|
+
/** @public */
|
|
676
|
+
export declare type RendererOptions = Omit<RenderOptions, 'serverData'> & {
|
|
677
|
+
serverData: ServerData;
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
/** @public */
|
|
681
|
+
export declare type RendererOutputOptions = Omit<RenderOptions, 'serverData'> & {
|
|
682
|
+
serverData: ServerData & {
|
|
683
|
+
documentHead?: DocumentHeadValue;
|
|
684
|
+
} & Record<string, unknown>;
|
|
685
|
+
};
|
|
686
|
+
|
|
594
687
|
export { RequestEvent }
|
|
595
688
|
|
|
596
689
|
export { RequestEventAction }
|
|
@@ -665,6 +758,18 @@ declare interface ServerConfig {
|
|
|
665
758
|
fetchOptions?: any;
|
|
666
759
|
}
|
|
667
760
|
|
|
761
|
+
/** @public The server data that is provided by Qwik Router during SSR rendering. It can be retrieved with `useServerData(key)` in the server, but it is not available in the client. */
|
|
762
|
+
export declare type ServerData = {
|
|
763
|
+
url: string;
|
|
764
|
+
requestHeaders: Record<string, string>;
|
|
765
|
+
locale: string | undefined;
|
|
766
|
+
nonce: string | undefined;
|
|
767
|
+
containerAttributes: Record<string, string> & {
|
|
768
|
+
[Q_ROUTE]: string;
|
|
769
|
+
};
|
|
770
|
+
qwikrouter: QwikRouterEnvData;
|
|
771
|
+
};
|
|
772
|
+
|
|
668
773
|
/** @public */
|
|
669
774
|
export declare type ServerFunction = {
|
|
670
775
|
(this: RequestEventBase, ...args: any[]): any;
|
|
@@ -788,6 +893,14 @@ export declare const usePreventNavigate$: (qrl: PreventNavigateCallback) => void
|
|
|
788
893
|
|
|
789
894
|
/* Excluded from this release type: usePreventNavigateQrl */
|
|
790
895
|
|
|
896
|
+
/**
|
|
897
|
+
* @public
|
|
898
|
+
* This hook initializes Qwik Router, providing the necessary context for it to work.
|
|
899
|
+
*
|
|
900
|
+
* This hook should be used once, at the root of your application.
|
|
901
|
+
*/
|
|
902
|
+
export declare const useQwikRouter: (props?: QwikRouterProps) => void;
|
|
903
|
+
|
|
791
904
|
/** @beta */
|
|
792
905
|
export declare const valibot$: ValibotConstructor;
|
|
793
906
|
|