@tanstack/router-core 1.167.0 → 1.167.2
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/dist/cjs/Matches.cjs +15 -12
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/config.cjs +9 -8
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/defer.cjs +37 -21
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/index.cjs +87 -89
- package/dist/cjs/isServer/client.cjs +5 -3
- package/dist/cjs/isServer/client.cjs.map +1 -1
- package/dist/cjs/isServer/development.cjs +5 -3
- package/dist/cjs/isServer/development.cjs.map +1 -1
- package/dist/cjs/isServer/server.cjs +5 -3
- package/dist/cjs/isServer/server.cjs.map +1 -1
- package/dist/cjs/link.cjs +5 -4
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/load-matches.cjs +619 -766
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/lru-cache.cjs +67 -64
- package/dist/cjs/lru-cache.cjs.map +1 -1
- package/dist/cjs/new-process-route-tree.cjs +707 -792
- package/dist/cjs/new-process-route-tree.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +20 -7
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/path.cjs +221 -232
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/qss.cjs +62 -28
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/redirect.cjs +44 -30
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/rewrite.cjs +56 -56
- package/dist/cjs/rewrite.cjs.map +1 -1
- package/dist/cjs/root.cjs +6 -4
- package/dist/cjs/root.cjs.map +1 -1
- package/dist/cjs/route.cjs +96 -105
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +1153 -1524
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -0
- package/dist/cjs/scroll-restoration.cjs +189 -207
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/searchMiddleware.cjs +48 -37
- package/dist/cjs/searchMiddleware.cjs.map +1 -1
- package/dist/cjs/searchParams.cjs +57 -45
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/ssr/client.cjs +6 -8
- package/dist/cjs/ssr/constants.cjs +6 -5
- package/dist/cjs/ssr/constants.cjs.map +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs +41 -59
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/handlerCallback.cjs +5 -4
- package/dist/cjs/ssr/handlerCallback.cjs.map +1 -1
- package/dist/cjs/ssr/headers.cjs +17 -26
- package/dist/cjs/ssr/headers.cjs.map +1 -1
- package/dist/cjs/ssr/json.cjs +8 -4
- package/dist/cjs/ssr/json.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/RawStream.cjs +268 -268
- package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +31 -32
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs +12 -12
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/transformer.cjs +45 -41
- package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
- package/dist/cjs/ssr/server.cjs +12 -14
- package/dist/cjs/ssr/ssr-client.cjs +173 -211
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-match-id.cjs +6 -5
- package/dist/cjs/ssr/ssr-match-id.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +266 -300
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +317 -337
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
- package/dist/cjs/ssr/tsrScript.cjs +6 -4
- package/dist/cjs/ssr/tsrScript.cjs.map +1 -1
- package/dist/cjs/ssr/tsrScript.d.cts +1 -0
- package/dist/cjs/utils/batch.cjs +13 -13
- package/dist/cjs/utils/batch.cjs.map +1 -1
- package/dist/cjs/utils.cjs +274 -208
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Matches.js +16 -13
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/config.js +10 -9
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/defer.js +37 -22
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/index.js +12 -82
- package/dist/esm/isServer/client.js +6 -5
- package/dist/esm/isServer/client.js.map +1 -1
- package/dist/esm/isServer/development.js +6 -5
- package/dist/esm/isServer/development.js.map +1 -1
- package/dist/esm/isServer/server.js +6 -5
- package/dist/esm/isServer/server.js.map +1 -1
- package/dist/esm/link.js +6 -5
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/load-matches.js +614 -765
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/lru-cache.js +68 -65
- package/dist/esm/lru-cache.js.map +1 -1
- package/dist/esm/new-process-route-tree.js +705 -797
- package/dist/esm/new-process-route-tree.js.map +1 -1
- package/dist/esm/not-found.js +21 -9
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/path.js +220 -241
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/qss.js +63 -30
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/redirect.js +45 -34
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/rewrite.js +57 -60
- package/dist/esm/rewrite.js.map +1 -1
- package/dist/esm/root.js +7 -5
- package/dist/esm/root.js.map +1 -1
- package/dist/esm/route.js +92 -105
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +2 -0
- package/dist/esm/router.js +1147 -1527
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.js +188 -213
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchMiddleware.js +48 -38
- package/dist/esm/searchMiddleware.js.map +1 -1
- package/dist/esm/searchParams.js +57 -48
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/ssr/client.js +1 -6
- package/dist/esm/ssr/constants.js +7 -7
- package/dist/esm/ssr/constants.js.map +1 -1
- package/dist/esm/ssr/createRequestHandler.js +39 -58
- package/dist/esm/ssr/createRequestHandler.js.map +1 -1
- package/dist/esm/ssr/handlerCallback.js +6 -5
- package/dist/esm/ssr/handlerCallback.js.map +1 -1
- package/dist/esm/ssr/headers.js +16 -26
- package/dist/esm/ssr/headers.js.map +1 -1
- package/dist/esm/ssr/json.js +9 -5
- package/dist/esm/ssr/json.js.map +1 -1
- package/dist/esm/ssr/serializer/RawStream.js +267 -273
- package/dist/esm/ssr/serializer/RawStream.js.map +1 -1
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js +31 -32
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -1
- package/dist/esm/ssr/serializer/seroval-plugins.js +10 -11
- package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -1
- package/dist/esm/ssr/serializer/transformer.js +44 -43
- package/dist/esm/ssr/serializer/transformer.js.map +1 -1
- package/dist/esm/ssr/server.js +2 -12
- package/dist/esm/ssr/ssr-client.js +169 -209
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-match-id.js +7 -7
- package/dist/esm/ssr/ssr-match-id.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +262 -300
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/ssr/transformStreamWithRouter.js +315 -338
- package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
- package/dist/esm/ssr/tsrScript.js +6 -5
- package/dist/esm/ssr/tsrScript.js.map +1 -1
- package/dist/esm/utils/batch.js +13 -14
- package/dist/esm/utils/batch.js.map +1 -1
- package/dist/esm/utils.js +273 -224
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +2 -0
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/ssr/client.cjs.map +0 -1
- package/dist/cjs/ssr/server.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/ssr/client.js.map +0 -1
- package/dist/esm/ssr/server.js.map +0 -1
package/dist/cjs/qss.cjs
CHANGED
|
@@ -1,36 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/qss.ts
|
|
2
|
+
/**
|
|
3
|
+
* Program is a reimplementation of the `qss` package:
|
|
4
|
+
* Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
|
|
5
|
+
* https://github.com/lukeed/qss/blob/master/license.md
|
|
6
|
+
*
|
|
7
|
+
* This reimplementation uses modern browser APIs
|
|
8
|
+
* (namely URLSearchParams) and TypeScript while still
|
|
9
|
+
* maintaining the original functionality and interface.
|
|
10
|
+
*
|
|
11
|
+
* Update: this implementation has also been mangled to
|
|
12
|
+
* fit exactly our use-case (single value per key in encoding).
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Encodes an object into a query string.
|
|
16
|
+
* @param obj - The object to encode into a query string.
|
|
17
|
+
* @param stringify - An optional custom stringify function.
|
|
18
|
+
* @returns The encoded query string.
|
|
19
|
+
* @example
|
|
20
|
+
* ```
|
|
21
|
+
* // Example input: encode({ token: 'foo', key: 'value' })
|
|
22
|
+
* // Expected output: "token=foo&key=value"
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
function encode(obj, stringify = String) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return result.toString();
|
|
26
|
+
const result = new URLSearchParams();
|
|
27
|
+
for (const key in obj) {
|
|
28
|
+
const val = obj[key];
|
|
29
|
+
if (val !== void 0) result.set(key, stringify(val));
|
|
30
|
+
}
|
|
31
|
+
return result.toString();
|
|
12
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Converts a string value to its appropriate type (string, number, boolean).
|
|
35
|
+
* @param mix - The string value to convert.
|
|
36
|
+
* @returns The converted value.
|
|
37
|
+
* @example
|
|
38
|
+
* // Example input: toValue("123")
|
|
39
|
+
* // Expected output: 123
|
|
40
|
+
*/
|
|
13
41
|
function toValue(str) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
42
|
+
if (!str) return "";
|
|
43
|
+
if (str === "false") return false;
|
|
44
|
+
if (str === "true") return true;
|
|
45
|
+
return +str * 0 === 0 && +str + "" === str ? +str : str;
|
|
18
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Decodes a query string into an object.
|
|
49
|
+
* @param str - The query string to decode.
|
|
50
|
+
* @returns The decoded key-value pairs in an object format.
|
|
51
|
+
* @example
|
|
52
|
+
* // Example input: decode("token=foo&key=value")
|
|
53
|
+
* // Expected output: { "token": "foo", "key": "value" }
|
|
54
|
+
*/
|
|
19
55
|
function decode(str) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
result[key] = [previousValue, toValue(value)];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
56
|
+
const searchParams = new URLSearchParams(str);
|
|
57
|
+
const result = Object.create(null);
|
|
58
|
+
for (const [key, value] of searchParams.entries()) {
|
|
59
|
+
const previousValue = result[key];
|
|
60
|
+
if (previousValue == null) result[key] = toValue(value);
|
|
61
|
+
else if (Array.isArray(previousValue)) previousValue.push(toValue(value));
|
|
62
|
+
else result[key] = [previousValue, toValue(value)];
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
33
65
|
}
|
|
66
|
+
//#endregion
|
|
34
67
|
exports.decode = decode;
|
|
35
68
|
exports.encode = encode;
|
|
36
|
-
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=qss.cjs.map
|
package/dist/cjs/qss.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qss.cjs","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n *\n * Update: this implementation has also been mangled to\n * fit exactly our use-case (single value per key in encoding).\n */\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param stringify - An optional custom stringify function.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(\n obj: Record<string, any>,\n stringify: (value: any) => string = String,\n): string {\n const result = new URLSearchParams()\n\n for (const key in obj) {\n const val = obj[key]\n if (val !== undefined) {\n result.set(key, stringify(val))\n }\n }\n\n return result.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(str: unknown) {\n if (!str) return ''\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any): any {\n const searchParams = new URLSearchParams(str)\n\n const result: Record<string, unknown> = Object.create(null)\n\n for (const [key, value] of searchParams.entries()) {\n const previousValue = result[key]\n if (previousValue == null) {\n result[key] = toValue(value)\n } else if (Array.isArray(previousValue)) {\n previousValue.push(toValue(value))\n } else {\n result[key] = [previousValue, toValue(value)]\n }\n }\n\n return result\n}\n"],"
|
|
1
|
+
{"version":3,"file":"qss.cjs","names":[],"sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n *\n * Update: this implementation has also been mangled to\n * fit exactly our use-case (single value per key in encoding).\n */\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param stringify - An optional custom stringify function.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(\n obj: Record<string, any>,\n stringify: (value: any) => string = String,\n): string {\n const result = new URLSearchParams()\n\n for (const key in obj) {\n const val = obj[key]\n if (val !== undefined) {\n result.set(key, stringify(val))\n }\n }\n\n return result.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(str: unknown) {\n if (!str) return ''\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any): any {\n const searchParams = new URLSearchParams(str)\n\n const result: Record<string, unknown> = Object.create(null)\n\n for (const [key, value] of searchParams.entries()) {\n const previousValue = result[key]\n if (previousValue == null) {\n result[key] = toValue(value)\n } else if (Array.isArray(previousValue)) {\n previousValue.push(toValue(value))\n } else {\n result[key] = [previousValue, toValue(value)]\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,OACd,KACA,YAAoC,QAC5B;CACR,MAAM,SAAS,IAAI,iBAAiB;AAEpC,MAAK,MAAM,OAAO,KAAK;EACrB,MAAM,MAAM,IAAI;AAChB,MAAI,QAAQ,KAAA,EACV,QAAO,IAAI,KAAK,UAAU,IAAI,CAAC;;AAInC,QAAO,OAAO,UAAU;;;;;;;;;;AAW1B,SAAS,QAAQ,KAAc;AAC7B,KAAI,CAAC,IAAK,QAAO;AAEjB,KAAI,QAAQ,QAAS,QAAO;AAC5B,KAAI,QAAQ,OAAQ,QAAO;AAC3B,QAAO,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;;;;;;;;;;AAUtD,SAAgB,OAAO,KAAe;CACpC,MAAM,eAAe,IAAI,gBAAgB,IAAI;CAE7C,MAAM,SAAkC,OAAO,OAAO,KAAK;AAE3D,MAAK,MAAM,CAAC,KAAK,UAAU,aAAa,SAAS,EAAE;EACjD,MAAM,gBAAgB,OAAO;AAC7B,MAAI,iBAAiB,KACnB,QAAO,OAAO,QAAQ,MAAM;WACnB,MAAM,QAAQ,cAAc,CACrC,eAAc,KAAK,QAAQ,MAAM,CAAC;MAElC,QAAO,OAAO,CAAC,eAAe,QAAQ,MAAM,CAAC;;AAIjD,QAAO"}
|
package/dist/cjs/redirect.cjs
CHANGED
|
@@ -1,42 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/redirect.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a redirect Response understood by TanStack Router.
|
|
4
|
+
*
|
|
5
|
+
* Use from route `loader`/`beforeLoad` or server functions to trigger a
|
|
6
|
+
* navigation. If `throw: true` is set, the redirect is thrown instead of
|
|
7
|
+
* returned. When an absolute `href` is supplied and `reloadDocument` is not
|
|
8
|
+
* set, a full-document navigation is inferred.
|
|
9
|
+
*
|
|
10
|
+
* @param opts Options for the redirect. Common fields:
|
|
11
|
+
* - `href`: absolute URL for external redirects; infers `reloadDocument`.
|
|
12
|
+
* - `statusCode`: HTTP status code to use (defaults to 307).
|
|
13
|
+
* - `headers`: additional headers to include on the Response.
|
|
14
|
+
* - Standard navigation options like `to`, `params`, `search`, `replace`,
|
|
15
|
+
* and `reloadDocument` for internal redirects.
|
|
16
|
+
* @returns A Response augmented with router navigation options.
|
|
17
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction
|
|
18
|
+
*/
|
|
3
19
|
function redirect(opts) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
headers
|
|
19
|
-
});
|
|
20
|
-
response.options = opts;
|
|
21
|
-
if (opts.throw) {
|
|
22
|
-
throw response;
|
|
23
|
-
}
|
|
24
|
-
return response;
|
|
20
|
+
opts.statusCode = opts.statusCode || opts.code || 307;
|
|
21
|
+
if (!opts._builtLocation && !opts.reloadDocument && typeof opts.href === "string") try {
|
|
22
|
+
new URL(opts.href);
|
|
23
|
+
opts.reloadDocument = true;
|
|
24
|
+
} catch {}
|
|
25
|
+
const headers = new Headers(opts.headers);
|
|
26
|
+
if (opts.href && headers.get("Location") === null) headers.set("Location", opts.href);
|
|
27
|
+
const response = new Response(null, {
|
|
28
|
+
status: opts.statusCode,
|
|
29
|
+
headers
|
|
30
|
+
});
|
|
31
|
+
response.options = opts;
|
|
32
|
+
if (opts.throw) throw response;
|
|
33
|
+
return response;
|
|
25
34
|
}
|
|
35
|
+
/** Check whether a value is a TanStack Router redirect Response. */
|
|
36
|
+
/** Check whether a value is a TanStack Router redirect Response. */
|
|
26
37
|
function isRedirect(obj) {
|
|
27
|
-
|
|
38
|
+
return obj instanceof Response && !!obj.options;
|
|
28
39
|
}
|
|
40
|
+
/** True if value is a redirect with a resolved `href` location. */
|
|
41
|
+
/** True if value is a redirect with a resolved `href` location. */
|
|
29
42
|
function isResolvedRedirect(obj) {
|
|
30
|
-
|
|
43
|
+
return isRedirect(obj) && !!obj.options.href;
|
|
31
44
|
}
|
|
45
|
+
/** Parse a serialized redirect object back into a redirect Response. */
|
|
46
|
+
/** Parse a serialized redirect object back into a redirect Response. */
|
|
32
47
|
function parseRedirect(obj) {
|
|
33
|
-
|
|
34
|
-
return redirect(obj);
|
|
35
|
-
}
|
|
36
|
-
return void 0;
|
|
48
|
+
if (obj !== null && typeof obj === "object" && obj.isSerializedRedirect) return redirect(obj);
|
|
37
49
|
}
|
|
50
|
+
//#endregion
|
|
38
51
|
exports.isRedirect = isRedirect;
|
|
39
52
|
exports.isResolvedRedirect = isResolvedRedirect;
|
|
40
53
|
exports.parseRedirect = parseRedirect;
|
|
41
54
|
exports.redirect = redirect;
|
|
42
|
-
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=redirect.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.cjs","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ParsedLocation } from './location'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n }\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (\n !opts._builtLocation &&\n !opts.reloadDocument &&\n typeof opts.href === 'string'\n ) {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"
|
|
1
|
+
{"version":3,"file":"redirect.cjs","names":[],"sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ParsedLocation } from './location'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n }\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (\n !opts._builtLocation &&\n !opts.reloadDocument &&\n typeof opts.href === 'string'\n ) {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkHA,SAAgB,SAOd,MACmD;AACnD,MAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAElD,KACE,CAAC,KAAK,kBACN,CAAC,KAAK,kBACN,OAAO,KAAK,SAAS,SAErB,KAAI;AACF,MAAI,IAAI,KAAK,KAAK;AAClB,OAAK,iBAAiB;SAChB;CAGV,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,KAAI,KAAK,QAAQ,QAAQ,IAAI,WAAW,KAAK,KAC3C,SAAQ,IAAI,YAAY,KAAK,KAAK;CAGpC,MAAM,WAAW,IAAI,SAAS,MAAM;EAClC,QAAQ,KAAK;EACb;EACD,CAAC;AAEA,UAA+D,UAC/D;AAEF,KAAI,KAAK,MACP,OAAM;AAGR,QAAO;;;;AAKT,SAAgB,WAAW,KAA8B;AACvD,QAAO,eAAe,YAAY,CAAC,CAAE,IAAY;;;;AAKnD,SAAgB,mBACd,KACoD;AACpD,QAAO,WAAW,IAAI,IAAI,CAAC,CAAC,IAAI,QAAQ;;;;AAK1C,SAAgB,cAAc,KAAU;AACtC,KAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,IAAI,qBACjD,QAAO,SAAS,IAAI"}
|
package/dist/cjs/rewrite.cjs
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const require_path = require("./path.cjs");
|
|
2
|
+
//#region src/rewrite.ts
|
|
3
|
+
/** Compose multiple rewrite pairs into a single in/out rewrite. */
|
|
4
|
+
/** Compose multiple rewrite pairs into a single in/out rewrite. */
|
|
4
5
|
function composeRewrites(rewrites) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return url;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
6
|
+
return {
|
|
7
|
+
input: ({ url }) => {
|
|
8
|
+
for (const rewrite of rewrites) url = executeRewriteInput(rewrite, url);
|
|
9
|
+
return url;
|
|
10
|
+
},
|
|
11
|
+
output: ({ url }) => {
|
|
12
|
+
for (let i = rewrites.length - 1; i >= 0; i--) url = executeRewriteOutput(rewrites[i], url);
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
19
16
|
}
|
|
17
|
+
/** Create a rewrite pair that strips/adds a basepath on input/output. */
|
|
18
|
+
/** Create a rewrite pair that strips/adds a basepath on input/output. */
|
|
20
19
|
function rewriteBasepath(opts) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
const trimmedBasepath = require_path.trimPath(opts.basepath);
|
|
21
|
+
const normalizedBasepath = `/${trimmedBasepath}`;
|
|
22
|
+
const normalizedBasepathWithSlash = `${normalizedBasepath}/`;
|
|
23
|
+
const checkBasepath = opts.caseSensitive ? normalizedBasepath : normalizedBasepath.toLowerCase();
|
|
24
|
+
const checkBasepathWithSlash = opts.caseSensitive ? normalizedBasepathWithSlash : normalizedBasepathWithSlash.toLowerCase();
|
|
25
|
+
return {
|
|
26
|
+
input: ({ url }) => {
|
|
27
|
+
const pathname = opts.caseSensitive ? url.pathname : url.pathname.toLowerCase();
|
|
28
|
+
if (pathname === checkBasepath) url.pathname = "/";
|
|
29
|
+
else if (pathname.startsWith(checkBasepathWithSlash)) url.pathname = url.pathname.slice(normalizedBasepath.length);
|
|
30
|
+
return url;
|
|
31
|
+
},
|
|
32
|
+
output: ({ url }) => {
|
|
33
|
+
url.pathname = require_path.joinPaths([
|
|
34
|
+
"/",
|
|
35
|
+
trimmedBasepath,
|
|
36
|
+
url.pathname
|
|
37
|
+
]);
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
41
|
}
|
|
42
|
+
/** Execute a location input rewrite if provided. */
|
|
43
|
+
/** Execute a location input rewrite if provided. */
|
|
42
44
|
function executeRewriteInput(rewrite, url) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return url;
|
|
45
|
+
const res = rewrite?.input?.({ url });
|
|
46
|
+
if (res) {
|
|
47
|
+
if (typeof res === "string") return new URL(res);
|
|
48
|
+
else if (res instanceof URL) return res;
|
|
49
|
+
}
|
|
50
|
+
return url;
|
|
52
51
|
}
|
|
52
|
+
/** Execute a location output rewrite if provided. */
|
|
53
|
+
/** Execute a location output rewrite if provided. */
|
|
53
54
|
function executeRewriteOutput(rewrite, url) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return url;
|
|
55
|
+
const res = rewrite?.output?.({ url });
|
|
56
|
+
if (res) {
|
|
57
|
+
if (typeof res === "string") return new URL(res);
|
|
58
|
+
else if (res instanceof URL) return res;
|
|
59
|
+
}
|
|
60
|
+
return url;
|
|
63
61
|
}
|
|
62
|
+
//#endregion
|
|
64
63
|
exports.composeRewrites = composeRewrites;
|
|
65
64
|
exports.executeRewriteInput = executeRewriteInput;
|
|
66
65
|
exports.executeRewriteOutput = executeRewriteOutput;
|
|
67
66
|
exports.rewriteBasepath = rewriteBasepath;
|
|
68
|
-
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=rewrite.cjs.map
|
package/dist/cjs/rewrite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite.cjs","sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const normalizedBasepath = `/${trimmedBasepath}`\n const normalizedBasepathWithSlash = `${normalizedBasepath}/`\n const checkBasepath = opts.caseSensitive\n ? normalizedBasepath\n : normalizedBasepath.toLowerCase()\n const checkBasepathWithSlash = opts.caseSensitive\n ? normalizedBasepathWithSlash\n : normalizedBasepathWithSlash.toLowerCase()\n\n return {\n input: ({ url }) => {\n const pathname = opts.caseSensitive\n ? url.pathname\n : url.pathname.toLowerCase()\n\n // Handle exact basepath match (e.g., /my-app -> /)\n if (pathname === checkBasepath) {\n url.pathname = '/'\n } else if (pathname.startsWith(checkBasepathWithSlash)) {\n // Handle basepath with trailing content (e.g., /my-app/users -> /users)\n url.pathname = url.pathname.slice(normalizedBasepath.length)\n }\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Execute a location input rewrite if provided. */\n/** Execute a location input rewrite if provided. */\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\n/** Execute a location output rewrite if provided. */\n/** Execute a location output rewrite if provided. */\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"
|
|
1
|
+
{"version":3,"file":"rewrite.cjs","names":[],"sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const normalizedBasepath = `/${trimmedBasepath}`\n const normalizedBasepathWithSlash = `${normalizedBasepath}/`\n const checkBasepath = opts.caseSensitive\n ? normalizedBasepath\n : normalizedBasepath.toLowerCase()\n const checkBasepathWithSlash = opts.caseSensitive\n ? normalizedBasepathWithSlash\n : normalizedBasepathWithSlash.toLowerCase()\n\n return {\n input: ({ url }) => {\n const pathname = opts.caseSensitive\n ? url.pathname\n : url.pathname.toLowerCase()\n\n // Handle exact basepath match (e.g., /my-app -> /)\n if (pathname === checkBasepath) {\n url.pathname = '/'\n } else if (pathname.startsWith(checkBasepathWithSlash)) {\n // Handle basepath with trailing content (e.g., /my-app/users -> /users)\n url.pathname = url.pathname.slice(normalizedBasepath.length)\n }\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Execute a location input rewrite if provided. */\n/** Execute a location input rewrite if provided. */\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\n/** Execute a location output rewrite if provided. */\n/** Execute a location output rewrite if provided. */\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"mappings":";;;;AAKA,SAAgB,gBAAgB,UAAkC;AAChE,QAAO;EACL,QAAQ,EAAE,UAAU;AAClB,QAAK,MAAM,WAAW,SACpB,OAAM,oBAAoB,SAAS,IAAI;AAEzC,UAAO;;EAET,SAAS,EAAE,UAAU;AACnB,QAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,IACxC,OAAM,qBAAqB,SAAS,IAAI,IAAI;AAE9C,UAAO;;EAEV;;;;AAKH,SAAgB,gBAAgB,MAG7B;CACD,MAAM,kBAAkB,aAAA,SAAS,KAAK,SAAS;CAC/C,MAAM,qBAAqB,IAAI;CAC/B,MAAM,8BAA8B,GAAG,mBAAmB;CAC1D,MAAM,gBAAgB,KAAK,gBACvB,qBACA,mBAAmB,aAAa;CACpC,MAAM,yBAAyB,KAAK,gBAChC,8BACA,4BAA4B,aAAa;AAE7C,QAAO;EACL,QAAQ,EAAE,UAAU;GAClB,MAAM,WAAW,KAAK,gBAClB,IAAI,WACJ,IAAI,SAAS,aAAa;AAG9B,OAAI,aAAa,cACf,KAAI,WAAW;YACN,SAAS,WAAW,uBAAuB,CAEpD,KAAI,WAAW,IAAI,SAAS,MAAM,mBAAmB,OAAO;AAE9D,UAAO;;EAET,SAAS,EAAE,UAAU;AACnB,OAAI,WAAW,aAAA,UAAU;IAAC;IAAK;IAAiB,IAAI;IAAS,CAAC;AAC9D,UAAO;;EAEV;;;;AAKH,SAAgB,oBACd,SACA,KACK;CACL,MAAM,MAAM,SAAS,QAAQ,EAAE,KAAK,CAAC;AACrC,KAAI;MACE,OAAO,QAAQ,SACjB,QAAO,IAAI,IAAI,IAAI;WACV,eAAe,IACxB,QAAO;;AAGX,QAAO;;;;AAKT,SAAgB,qBACd,SACA,KACK;CACL,MAAM,MAAM,SAAS,SAAS,EAAE,KAAK,CAAC;AACtC,KAAI;MACE,OAAO,QAAQ,SACjB,QAAO,IAAI,IAAI,IAAI;WACV,eAAe,IACxB,QAAO;;AAGX,QAAO"}
|
package/dist/cjs/root.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/root.ts
|
|
2
|
+
/** Stable identifier used for the root route in a route tree. */
|
|
3
|
+
var rootRouteId = "__root__";
|
|
4
|
+
//#endregion
|
|
4
5
|
exports.rootRouteId = rootRouteId;
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=root.cjs.map
|
package/dist/cjs/root.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.cjs","sources":["../../src/root.ts"],"sourcesContent":["/** Stable identifier used for the root route in a route tree. */\nexport const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"
|
|
1
|
+
{"version":3,"file":"root.cjs","names":[],"sources":["../../src/root.ts"],"sourcesContent":["/** Stable identifier used for the root route in a route tree. */\nexport const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"mappings":";;AACA,IAAa,cAAc"}
|
package/dist/cjs/route.cjs
CHANGED
|
@@ -1,108 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
this.redirect = (opts) => redirect.redirect({ from: this.id, ...opts });
|
|
97
|
-
this.id = id;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
class BaseRootRoute extends BaseRoute {
|
|
101
|
-
constructor(options) {
|
|
102
|
-
super(options);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_path = require("./path.cjs");
|
|
3
|
+
const require_not_found = require("./not-found.cjs");
|
|
4
|
+
const require_root = require("./root.cjs");
|
|
5
|
+
const require_redirect = require("./redirect.cjs");
|
|
6
|
+
let tiny_invariant = require("tiny-invariant");
|
|
7
|
+
tiny_invariant = require_runtime.__toESM(tiny_invariant);
|
|
8
|
+
//#region src/route.ts
|
|
9
|
+
var BaseRoute = class {
|
|
10
|
+
get to() {
|
|
11
|
+
return this._to;
|
|
12
|
+
}
|
|
13
|
+
get id() {
|
|
14
|
+
return this._id;
|
|
15
|
+
}
|
|
16
|
+
get path() {
|
|
17
|
+
return this._path;
|
|
18
|
+
}
|
|
19
|
+
get fullPath() {
|
|
20
|
+
return this._fullPath;
|
|
21
|
+
}
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.init = (opts) => {
|
|
24
|
+
this.originalIndex = opts.originalIndex;
|
|
25
|
+
const options = this.options;
|
|
26
|
+
const isRoot = !options?.path && !options?.id;
|
|
27
|
+
this.parentRoute = this.options.getParentRoute?.();
|
|
28
|
+
if (isRoot) this._path = require_root.rootRouteId;
|
|
29
|
+
else if (!this.parentRoute) (0, tiny_invariant.default)(false, `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`);
|
|
30
|
+
let path = isRoot ? require_root.rootRouteId : options?.path;
|
|
31
|
+
if (path && path !== "/") path = require_path.trimPathLeft(path);
|
|
32
|
+
const customId = options?.id || path;
|
|
33
|
+
let id = isRoot ? require_root.rootRouteId : require_path.joinPaths([this.parentRoute.id === "__root__" ? "" : this.parentRoute.id, customId]);
|
|
34
|
+
if (path === "__root__") path = "/";
|
|
35
|
+
if (id !== "__root__") id = require_path.joinPaths(["/", id]);
|
|
36
|
+
const fullPath = id === "__root__" ? "/" : require_path.joinPaths([this.parentRoute.fullPath, path]);
|
|
37
|
+
this._path = path;
|
|
38
|
+
this._id = id;
|
|
39
|
+
this._fullPath = fullPath;
|
|
40
|
+
this._to = require_path.trimPathRight(fullPath);
|
|
41
|
+
};
|
|
42
|
+
this.addChildren = (children) => {
|
|
43
|
+
return this._addFileChildren(children);
|
|
44
|
+
};
|
|
45
|
+
this._addFileChildren = (children) => {
|
|
46
|
+
if (Array.isArray(children)) this.children = children;
|
|
47
|
+
if (typeof children === "object" && children !== null) this.children = Object.values(children);
|
|
48
|
+
return this;
|
|
49
|
+
};
|
|
50
|
+
this._addFileTypes = () => {
|
|
51
|
+
return this;
|
|
52
|
+
};
|
|
53
|
+
this.updateLoader = (options) => {
|
|
54
|
+
Object.assign(this.options, options);
|
|
55
|
+
return this;
|
|
56
|
+
};
|
|
57
|
+
this.update = (options) => {
|
|
58
|
+
Object.assign(this.options, options);
|
|
59
|
+
return this;
|
|
60
|
+
};
|
|
61
|
+
this.lazy = (lazyFn) => {
|
|
62
|
+
this.lazyFn = lazyFn;
|
|
63
|
+
return this;
|
|
64
|
+
};
|
|
65
|
+
this.redirect = (opts) => require_redirect.redirect({
|
|
66
|
+
from: this.fullPath,
|
|
67
|
+
...opts
|
|
68
|
+
});
|
|
69
|
+
this.options = options || {};
|
|
70
|
+
this.isRoot = !options?.getParentRoute;
|
|
71
|
+
if (options?.id && options?.path) throw new Error(`Route cannot have both an 'id' and a 'path' option.`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var BaseRouteApi = class {
|
|
75
|
+
constructor({ id }) {
|
|
76
|
+
this.notFound = (opts) => {
|
|
77
|
+
return require_not_found.notFound({
|
|
78
|
+
routeId: this.id,
|
|
79
|
+
...opts
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
this.redirect = (opts) => require_redirect.redirect({
|
|
83
|
+
from: this.id,
|
|
84
|
+
...opts
|
|
85
|
+
});
|
|
86
|
+
this.id = id;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var BaseRootRoute = class extends BaseRoute {
|
|
90
|
+
constructor(options) {
|
|
91
|
+
super(options);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
105
95
|
exports.BaseRootRoute = BaseRootRoute;
|
|
106
96
|
exports.BaseRoute = BaseRoute;
|
|
107
97
|
exports.BaseRouteApi = BaseRouteApi;
|
|
108
|
-
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=route.cjs.map
|