expo-router 3.5.16 → 3.5.17

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.
@@ -1 +1 @@
1
- {"version":3,"file":"getServerManifest.d.ts","sourceRoot":"","sources":["../src/getServerManifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,MAAM,MAAM,+BAA+B,CAAC,MAAM,GAAG,MAAM,IAAI;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,MAAM,GAAG,MAAM,IAAI;IACxD,SAAS,EAAE,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;IACrD,UAAU,EAAE,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;IACtD,cAAc,EAAE,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;CAC3D,CAAC;AAEF,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;CACZ;AAmBD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,0BAA0B,CA6C9E;AAmJD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM;;;;EAgB3C"}
1
+ {"version":3,"file":"getServerManifest.d.ts","sourceRoot":"","sources":["../src/getServerManifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,MAAM,MAAM,+BAA+B,CAAC,MAAM,GAAG,MAAM,IAAI;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,MAAM,GAAG,MAAM,IAAI;IACxD,SAAS,EAAE,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;IACrD,UAAU,EAAE,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;IACtD,cAAc,EAAE,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;CAC3D,CAAC;AAEF,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;CACZ;AAmBD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,0BAA0B,CA0C9E;AAmJD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM;;;;EAgB3C"}
@@ -19,9 +19,11 @@ function uniqueBy(arr, key) {
19
19
  }
20
20
  // Given a nested route tree, return a flattened array of all routes that can be matched.
21
21
  function getServerManifest(route) {
22
- function getFlatNodes(route) {
22
+ function getFlatNodes(route, parentRoute = '') {
23
+ // Use a recreated route instead of contextKey because we duplicate nodes to support array syntax.
24
+ const absoluteRoute = [parentRoute, route.route].filter(Boolean).join('/');
23
25
  if (route.children.length) {
24
- return route.children.map((child) => getFlatNodes(child)).flat();
26
+ return route.children.map((child) => getFlatNodes(child, absoluteRoute)).flat();
25
27
  }
26
28
  // API Routes are handled differently to HTML routes because they have no nested behavior.
27
29
  // An HTML route can be different based on parent segments due to layout routes, therefore multiple
@@ -31,29 +33,29 @@ function getServerManifest(route) {
31
33
  key = (0, matchers_1.getContextKey)(route.contextKey).replace(/\/index$/, '') ?? '/';
32
34
  }
33
35
  else {
34
- key = (0, matchers_1.getContextKey)(route.route).replace(/\/index$/, '') ?? '/';
36
+ key = (0, matchers_1.getContextKey)(absoluteRoute).replace(/\/index$/, '') ?? '/';
35
37
  }
36
- return [[key, route]];
38
+ return [[key, '/' + absoluteRoute, route]];
37
39
  }
38
40
  // Remove duplicates from the runtime manifest which expands array syntax.
39
41
  const flat = getFlatNodes(route)
40
- .sort(([, a], [, b]) => (0, sortRoutes_1.sortRoutes)(b, a))
42
+ .sort(([, , a], [, , b]) => (0, sortRoutes_1.sortRoutes)(b, a))
41
43
  .reverse();
42
- const apiRoutes = uniqueBy(flat.filter(([, route]) => route.type === 'api'), ([path]) => path);
43
- const otherRoutes = uniqueBy(flat.filter(([, route]) => route.type === 'route'), ([path]) => path);
44
- const standardRoutes = otherRoutes.filter(([, route]) => !isNotFoundRoute(route));
45
- const notFoundRoutes = otherRoutes.filter(([, route]) => isNotFoundRoute(route));
44
+ const apiRoutes = uniqueBy(flat.filter(([, , route]) => route.type === 'api'), ([path]) => path);
45
+ const otherRoutes = uniqueBy(flat.filter(([, , route]) => route.type === 'route'), ([path]) => path);
46
+ const standardRoutes = otherRoutes.filter(([, , route]) => !isNotFoundRoute(route));
47
+ const notFoundRoutes = otherRoutes.filter(([, , route]) => isNotFoundRoute(route));
46
48
  return {
47
- apiRoutes: getMatchableManifestForPaths(apiRoutes.map(([normalizedRoutePath, node]) => [normalizedRoutePath, node])),
48
- htmlRoutes: getMatchableManifestForPaths(standardRoutes.map(([normalizedRoutePath, node]) => [normalizedRoutePath, node])),
49
- notFoundRoutes: getMatchableManifestForPaths(notFoundRoutes.map(([normalizedRoutePath, node]) => [normalizedRoutePath, node])),
49
+ apiRoutes: getMatchableManifestForPaths(apiRoutes),
50
+ htmlRoutes: getMatchableManifestForPaths(standardRoutes),
51
+ notFoundRoutes: getMatchableManifestForPaths(notFoundRoutes),
50
52
  };
51
53
  }
52
54
  exports.getServerManifest = getServerManifest;
53
55
  function getMatchableManifestForPaths(paths) {
54
- return paths.map((normalizedRoutePath) => {
55
- const matcher = getNamedRouteRegex(normalizedRoutePath[0], (0, matchers_1.getContextKey)(normalizedRoutePath[1].route), normalizedRoutePath[1].contextKey);
56
- if (normalizedRoutePath[1].generated) {
56
+ return paths.map(([normalizedRoutePath, absoluteRoute, node]) => {
57
+ const matcher = getNamedRouteRegex(normalizedRoutePath, absoluteRoute, node.contextKey);
58
+ if (node.generated) {
57
59
  matcher.generated = true;
58
60
  }
59
61
  return matcher;
@@ -1 +1 @@
1
- {"version":3,"file":"getServerManifest.js","sourceRoot":"","sources":["../src/getServerManifest.ts"],"names":[],"mappings":";;;AAUA,yCAA2D;AAC3D,6CAA0C;AA4B1C,SAAS,eAAe,CAAC,KAAgB;IACvC,OAAO,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3E,CAAC;AAED,SAAS,QAAQ,CAAI,GAAQ,EAAE,GAAwB;IACrD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,yFAAyF;AACzF,SA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OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;KAC7C;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,IAAI,GAAG,KAAK,CAAC;IAEjB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,QAAQ,GAAG,IAAI,CAAC;QAChB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACxB,MAAM,GAAG,IAAI,CAAC;QACd,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtB;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC;AAhBD,wCAgBC","sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n * Copyright © 2023 Vercel, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Based on https://github.com/vercel/next.js/blob/1df2686bc9964f1a86c444701fa5cbf178669833/packages/next/src/shared/lib/router/utils/route-regex.ts\n */\nimport type { RouteNode } from './Route';\nimport { getContextKey, matchGroupName } from './matchers';\nimport { sortRoutes } from './sortRoutes';\n\n// TODO: Share these types across cli, server, router, etc.\nexport type ExpoRouterServerManifestV1Route<TRegex = string> = {\n file: string;\n page: string;\n routeKeys: Record<string, string>;\n namedRegex: TRegex;\n generated?: boolean;\n};\n\nexport type ExpoRouterServerManifestV1<TRegex = string> = {\n apiRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n htmlRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n notFoundRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n};\n\nexport interface Group {\n pos: number;\n repeat: boolean;\n optional: boolean;\n}\n\nexport interface RouteRegex {\n groups: Record<string, Group>;\n re: RegExp;\n}\n\nfunction isNotFoundRoute(route: RouteNode) {\n return route.dynamic && route.dynamic[route.dynamic.length - 1].notFound;\n}\n\nfunction uniqueBy<T>(arr: T[], key: (item: T) => string): T[] {\n const seen = new Set<string>();\n return arr.filter((item) => {\n const id = key(item);\n if (seen.has(id)) {\n return false;\n }\n seen.add(id);\n return true;\n });\n}\n\n// Given a nested route tree, return a flattened array of all routes that can be matched.\nexport function getServerManifest(route: RouteNode): ExpoRouterServerManifestV1 {\n function getFlatNodes(route: RouteNode): [string, RouteNode][] {\n if (route.children.length) {\n return route.children.map((child) => getFlatNodes(child)).flat();\n }\n\n // API Routes are handled differently to HTML routes because they have no nested behavior.\n // An HTML route can be different based on parent segments due to layout routes, therefore multiple\n // copies should be rendered. However, an API route is always the same regardless of parent segments.\n let key: string;\n if (route.type === 'api') {\n key = getContextKey(route.contextKey).replace(/\\/index$/, '') ?? '/';\n } else {\n key = getContextKey(route.route).replace(/\\/index$/, '') ?? '/';\n }\n return [[key, route]];\n }\n\n // Remove duplicates from the runtime manifest which expands array syntax.\n const flat = getFlatNodes(route)\n .sort(([, a], [, b]) => sortRoutes(b, a))\n .reverse();\n\n const apiRoutes = uniqueBy(\n flat.filter(([, route]) => route.type === 'api'),\n ([path]) => path\n );\n const otherRoutes = uniqueBy(\n flat.filter(([, route]) => route.type === 'route'),\n ([path]) => path\n );\n const standardRoutes = otherRoutes.filter(([, route]) => !isNotFoundRoute(route));\n const notFoundRoutes = otherRoutes.filter(([, route]) => isNotFoundRoute(route));\n\n return {\n apiRoutes: getMatchableManifestForPaths(\n apiRoutes.map(([normalizedRoutePath, node]) => [normalizedRoutePath, node])\n ),\n htmlRoutes: getMatchableManifestForPaths(\n standardRoutes.map(([normalizedRoutePath, node]) => [normalizedRoutePath, node])\n ),\n notFoundRoutes: getMatchableManifestForPaths(\n notFoundRoutes.map(([normalizedRoutePath, node]) => [normalizedRoutePath, node])\n ),\n };\n}\n\nfunction getMatchableManifestForPaths(\n paths: [string, RouteNode][]\n): ExpoRouterServerManifestV1Route[] {\n return paths.map((normalizedRoutePath) => {\n const matcher: ExpoRouterServerManifestV1Route = getNamedRouteRegex(\n normalizedRoutePath[0],\n getContextKey(normalizedRoutePath[1].route),\n normalizedRoutePath[1].contextKey\n );\n if (normalizedRoutePath[1].generated) {\n matcher.generated = true;\n }\n return matcher;\n });\n}\n\nfunction getNamedRouteRegex(\n normalizedRoute: string,\n page: string,\n file: string\n): ExpoRouterServerManifestV1Route {\n const result = getNamedParametrizedRoute(normalizedRoute);\n return {\n file,\n page,\n namedRegex: `^${result.namedParameterizedRoute}(?:/)?$`,\n routeKeys: result.routeKeys,\n };\n}\n\n/**\n * Builds a function to generate a minimal routeKey using only a-z and minimal\n * number of characters.\n */\nfunction buildGetSafeRouteKey() {\n let currentCharCode = 96; // Starting one before 'a' to make the increment logic simpler\n let currentLength = 1;\n\n return () => {\n let result = '';\n let incrementNext = true;\n\n // Iterate from right to left to build the key\n for (let i = 0; i < currentLength; i++) {\n if (incrementNext) {\n currentCharCode++;\n if (currentCharCode > 122) {\n currentCharCode = 97; // Reset to 'a'\n incrementNext = true; // Continue to increment the next character\n } else {\n incrementNext = false;\n }\n }\n result = String.fromCharCode(currentCharCode) + result;\n }\n\n // If all characters are 'z', increase the length of the key\n if (incrementNext) {\n currentLength++;\n currentCharCode = 96; // This will make the next key start with 'a'\n }\n\n return result;\n };\n}\n\nfunction removeTrailingSlash(route: string): string {\n return route.replace(/\\/$/, '') || '/';\n}\n\nfunction getNamedParametrizedRoute(route: string) {\n const segments = removeTrailingSlash(route).slice(1).split('/');\n const getSafeRouteKey = buildGetSafeRouteKey();\n const routeKeys: Record<string, string> = {};\n return {\n namedParameterizedRoute: segments\n .map((segment, index) => {\n if (segment === '+not-found' && index === segments.length - 1) {\n segment = '[...not-found]';\n }\n if (/^\\[.*\\]$/.test(segment)) {\n const { name, optional, repeat } = parseParameter(segment);\n // replace any non-word characters since they can break\n // the named regex\n let cleanedKey = name.replace(/\\W/g, '');\n let invalidKey = false;\n\n // check if the key is still invalid and fallback to using a known\n // safe key\n if (cleanedKey.length === 0 || cleanedKey.length > 30) {\n invalidKey = true;\n }\n if (!isNaN(parseInt(cleanedKey.slice(0, 1), 10))) {\n invalidKey = true;\n }\n\n // Prevent duplicates after sanitizing the key\n if (cleanedKey in routeKeys) {\n invalidKey = true;\n }\n\n if (invalidKey) {\n cleanedKey = getSafeRouteKey();\n }\n\n routeKeys[cleanedKey] = name;\n return repeat\n ? optional\n ? `(?:/(?<${cleanedKey}>.+?))?`\n : `/(?<${cleanedKey}>.+?)`\n : `/(?<${cleanedKey}>[^/]+?)`;\n } else if (/^\\(.*\\)$/.test(segment)) {\n const groupName = matchGroupName(segment)!\n .split(',')\n .map((group) => group.trim())\n .filter(Boolean);\n if (groupName.length > 1) {\n const optionalSegment = `\\\\((?:${groupName.map(escapeStringRegexp).join('|')})\\\\)`;\n // Make section optional\n return `(?:/${optionalSegment})?`;\n } else {\n // Use simpler regex for single groups\n return `(?:/${escapeStringRegexp(segment)})?`;\n }\n } else {\n return `/${escapeStringRegexp(segment)}`;\n }\n })\n .join(''),\n routeKeys,\n };\n}\n\n// regexp is based on https://github.com/sindresorhus/escape-string-regexp\nconst reHasRegExp = /[|\\\\{}()[\\]^$+*?.-]/;\nconst reReplaceRegExp = /[|\\\\{}()[\\]^$+*?.-]/g;\n\nfunction escapeStringRegexp(str: string) {\n // see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23\n if (reHasRegExp.test(str)) {\n return str.replace(reReplaceRegExp, '\\\\$&');\n }\n return str;\n}\n\nexport function parseParameter(param: string) {\n let repeat = false;\n let optional = false;\n let name = param;\n\n if (/^\\[.*\\]$/.test(name)) {\n optional = true;\n name = name.slice(1, -1);\n }\n\n if (/^\\.\\.\\./.test(name)) {\n repeat = true;\n name = name.slice(3);\n }\n\n return { name, repeat, optional };\n}\n"]}
1
+ {"version":3,"file":"getServerManifest.js","sourceRoot":"","sources":["../src/getServerManifest.ts"],"names":[],"mappings":";;;AAUA,yCAA2D;AAC3D,6CAA0C;AA4B1C,SAAS,eAAe,CAAC,KAAgB;IACvC,OAAO,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3E,CAAC;AAED,SAAS,QAAQ,CAAI,GAAQ,EAAE,GAAwB;IACrD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,yFAAyF;AACzF,SAAgB,iBAAiB,CAAC,KAAgB;IAChD,SAAS,YAAY,CAAC,KAAgB,EAAE,cAAsB,EAAE;QAC9D,kGAAkG;QAClG,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3E,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;YACzB,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACjF;QAED,0FAA0F;QAC1F,mGAAmG;QACnG,qGAAqG;QACrG,IAAI,GAAW,CAAC;QAChB,IAAI,K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 Industries.\n * Copyright © 2023 Vercel, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Based on https://github.com/vercel/next.js/blob/1df2686bc9964f1a86c444701fa5cbf178669833/packages/next/src/shared/lib/router/utils/route-regex.ts\n */\nimport type { RouteNode } from './Route';\nimport { getContextKey, matchGroupName } from './matchers';\nimport { sortRoutes } from './sortRoutes';\n\n// TODO: Share these types across cli, server, router, etc.\nexport type ExpoRouterServerManifestV1Route<TRegex = string> = {\n file: string;\n page: string;\n routeKeys: Record<string, string>;\n namedRegex: TRegex;\n generated?: boolean;\n};\n\nexport type ExpoRouterServerManifestV1<TRegex = string> = {\n apiRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n htmlRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n notFoundRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n};\n\nexport interface Group {\n pos: number;\n repeat: boolean;\n optional: boolean;\n}\n\nexport interface RouteRegex {\n groups: Record<string, Group>;\n re: RegExp;\n}\n\nfunction isNotFoundRoute(route: RouteNode) {\n return route.dynamic && route.dynamic[route.dynamic.length - 1].notFound;\n}\n\nfunction uniqueBy<T>(arr: T[], key: (item: T) => string): T[] {\n const seen = new Set<string>();\n return arr.filter((item) => {\n const id = key(item);\n if (seen.has(id)) {\n return false;\n }\n seen.add(id);\n return true;\n });\n}\n\n// Given a nested route tree, return a flattened array of all routes that can be matched.\nexport function getServerManifest(route: RouteNode): ExpoRouterServerManifestV1 {\n function getFlatNodes(route: RouteNode, parentRoute: string = ''): [string, string, RouteNode][] {\n // Use a recreated route instead of contextKey because we duplicate nodes to support array syntax.\n const absoluteRoute = [parentRoute, route.route].filter(Boolean).join('/');\n\n if (route.children.length) {\n return route.children.map((child) => getFlatNodes(child, absoluteRoute)).flat();\n }\n\n // API Routes are handled differently to HTML routes because they have no nested behavior.\n // An HTML route can be different based on parent segments due to layout routes, therefore multiple\n // copies should be rendered. However, an API route is always the same regardless of parent segments.\n let key: string;\n if (route.type === 'api') {\n key = getContextKey(route.contextKey).replace(/\\/index$/, '') ?? '/';\n } else {\n key = getContextKey(absoluteRoute).replace(/\\/index$/, '') ?? '/';\n }\n return [[key, '/' + absoluteRoute, route]];\n }\n\n // Remove duplicates from the runtime manifest which expands array syntax.\n const flat = getFlatNodes(route)\n .sort(([, , a], [, , b]) => sortRoutes(b, a))\n .reverse();\n\n const apiRoutes = uniqueBy(\n flat.filter(([, , route]) => route.type === 'api'),\n ([path]) => path\n );\n const otherRoutes = uniqueBy(\n flat.filter(([, , route]) => route.type === 'route'),\n ([path]) => path\n );\n const standardRoutes = otherRoutes.filter(([, , route]) => !isNotFoundRoute(route));\n const notFoundRoutes = otherRoutes.filter(([, , route]) => isNotFoundRoute(route));\n\n return {\n apiRoutes: getMatchableManifestForPaths(apiRoutes),\n htmlRoutes: getMatchableManifestForPaths(standardRoutes),\n notFoundRoutes: getMatchableManifestForPaths(notFoundRoutes),\n };\n}\n\nfunction getMatchableManifestForPaths(\n paths: [string, string, RouteNode][]\n): ExpoRouterServerManifestV1Route[] {\n return paths.map(([normalizedRoutePath, absoluteRoute, node]) => {\n const matcher: ExpoRouterServerManifestV1Route = getNamedRouteRegex(\n normalizedRoutePath,\n absoluteRoute,\n node.contextKey\n );\n if (node.generated) {\n matcher.generated = true;\n }\n return matcher;\n });\n}\n\nfunction getNamedRouteRegex(\n normalizedRoute: string,\n page: string,\n file: string\n): ExpoRouterServerManifestV1Route {\n const result = getNamedParametrizedRoute(normalizedRoute);\n return {\n file,\n page,\n namedRegex: `^${result.namedParameterizedRoute}(?:/)?$`,\n routeKeys: result.routeKeys,\n };\n}\n\n/**\n * Builds a function to generate a minimal routeKey using only a-z and minimal\n * number of characters.\n */\nfunction buildGetSafeRouteKey() {\n let currentCharCode = 96; // Starting one before 'a' to make the increment logic simpler\n let currentLength = 1;\n\n return () => {\n let result = '';\n let incrementNext = true;\n\n // Iterate from right to left to build the key\n for (let i = 0; i < currentLength; i++) {\n if (incrementNext) {\n currentCharCode++;\n if (currentCharCode > 122) {\n currentCharCode = 97; // Reset to 'a'\n incrementNext = true; // Continue to increment the next character\n } else {\n incrementNext = false;\n }\n }\n result = String.fromCharCode(currentCharCode) + result;\n }\n\n // If all characters are 'z', increase the length of the key\n if (incrementNext) {\n currentLength++;\n currentCharCode = 96; // This will make the next key start with 'a'\n }\n\n return result;\n };\n}\n\nfunction removeTrailingSlash(route: string): string {\n return route.replace(/\\/$/, '') || '/';\n}\n\nfunction getNamedParametrizedRoute(route: string) {\n const segments = removeTrailingSlash(route).slice(1).split('/');\n const getSafeRouteKey = buildGetSafeRouteKey();\n const routeKeys: Record<string, string> = {};\n return {\n namedParameterizedRoute: segments\n .map((segment, index) => {\n if (segment === '+not-found' && index === segments.length - 1) {\n segment = '[...not-found]';\n }\n if (/^\\[.*\\]$/.test(segment)) {\n const { name, optional, repeat } = parseParameter(segment);\n // replace any non-word characters since they can break\n // the named regex\n let cleanedKey = name.replace(/\\W/g, '');\n let invalidKey = false;\n\n // check if the key is still invalid and fallback to using a known\n // safe key\n if (cleanedKey.length === 0 || cleanedKey.length > 30) {\n invalidKey = true;\n }\n if (!isNaN(parseInt(cleanedKey.slice(0, 1), 10))) {\n invalidKey = true;\n }\n\n // Prevent duplicates after sanitizing the key\n if (cleanedKey in routeKeys) {\n invalidKey = true;\n }\n\n if (invalidKey) {\n cleanedKey = getSafeRouteKey();\n }\n\n routeKeys[cleanedKey] = name;\n return repeat\n ? optional\n ? `(?:/(?<${cleanedKey}>.+?))?`\n : `/(?<${cleanedKey}>.+?)`\n : `/(?<${cleanedKey}>[^/]+?)`;\n } else if (/^\\(.*\\)$/.test(segment)) {\n const groupName = matchGroupName(segment)!\n .split(',')\n .map((group) => group.trim())\n .filter(Boolean);\n if (groupName.length > 1) {\n const optionalSegment = `\\\\((?:${groupName.map(escapeStringRegexp).join('|')})\\\\)`;\n // Make section optional\n return `(?:/${optionalSegment})?`;\n } else {\n // Use simpler regex for single groups\n return `(?:/${escapeStringRegexp(segment)})?`;\n }\n } else {\n return `/${escapeStringRegexp(segment)}`;\n }\n })\n .join(''),\n routeKeys,\n };\n}\n\n// regexp is based on https://github.com/sindresorhus/escape-string-regexp\nconst reHasRegExp = /[|\\\\{}()[\\]^$+*?.-]/;\nconst reReplaceRegExp = /[|\\\\{}()[\\]^$+*?.-]/g;\n\nfunction escapeStringRegexp(str: string) {\n // see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23\n if (reHasRegExp.test(str)) {\n return str.replace(reReplaceRegExp, '\\\\$&');\n }\n return str;\n}\n\nexport function parseParameter(param: string) {\n let repeat = false;\n let optional = false;\n let name = param;\n\n if (/^\\[.*\\]$/.test(name)) {\n optional = true;\n name = name.slice(1, -1);\n }\n\n if (/^\\.\\.\\./.test(name)) {\n repeat = true;\n name = name.slice(3);\n }\n\n return { name, repeat, optional };\n}\n"]}
package/build/hooks.d.ts CHANGED
@@ -45,8 +45,9 @@ export declare function usePathname(): string;
45
45
  */
46
46
  export declare function useGlobalSearchParams<TParams extends SearchParams = SearchParams>(): Partial<TParams>;
47
47
  /**
48
- * Returns the URL search parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: "bar" }`.
48
+ * Returns the URL parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: "bar" }`.
49
49
  * This is useful for stacks where you may push a new screen that changes the query parameters.
50
+ * For dynamic routes, both the route parameters and the search parameters are returned.
50
51
  *
51
52
  * To observe updates even when the invoking route is not focused, use `useGlobalSearchParams()`.
52
53
  */
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAEtD,wBAAgB,sBAAsB,kDAErC;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AAW,IAAI,MAAM,CAEpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,YAAY,GAAG,YAAY,KACxC,OAAO,CAAC,OAAO,CAAC,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,SAAS,YAAY,GAAG,YAAY,KACxC,OAAO,CAAC,OAAO,CAAC,CAwBpB"}
package/build/hooks.js CHANGED
@@ -90,8 +90,9 @@ function useGlobalSearchParams() {
90
90
  }
91
91
  exports.useGlobalSearchParams = useGlobalSearchParams;
92
92
  /**
93
- * Returns the URL search parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: "bar" }`.
93
+ * Returns the URL parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: "bar" }`.
94
94
  * This is useful for stacks where you may push a new screen that changes the query parameters.
95
+ * For dynamic routes, both the route parameters and the search parameters are returned.
95
96
  *
96
97
  * To observe updates even when the invoking route is not focused, use `useGlobalSearchParams()`.
97
98
  */
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAkE;AAClE,kDAA0B;AAE1B,8DAA0F;AAK1F,SAAgB,sBAAsB;IACpC,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,wDAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,oCAEC;AAED,wFAAwF;AACxF,SAAgB,iBAAiB;IAC/B,OAAO,oBAAK,CAAC,aAAa,CAAC,OAAO,CAAC;AACrC,CAAC;AAFD,8CAEC;AAED,uJAAuJ;AACvJ,SAAgB,yBAAyB;IACvC,OAAO,oBAAK,CAAC,aAAa,CAAC;AAC7B,CAAC;AAFD,8DAEC;AAED,SAAgB,SAAS;IACvB,OAAO,eAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,IAA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AK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;oBACd,IAAI;wBACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC;qBAC9B;oBAAC,MAAM;wBACN,OAAO,CAAC,CAAC;qBACV;gBACH,CAAC,CAAC;aACH,CAAC;SACH;aAAM;YACL,IAAI;gBACF,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAe,CAAC,CAAC,CAAC;aACnD;YAAC,MAAM;gBACN,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC,CAAC,CACiB,CAAC;AACxB,CAAC;AA1BD,oDA0BC","sourcesContent":["import { NavigationRouteContext } from '@react-navigation/native';\nimport React from 'react';\n\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { ExpoRouter } from '../types/expo-router';\n\ntype SearchParams = Record<string, string | string[]>;\n\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/** @deprecated use `useNavigationContainerRef()` instead, which returns a React ref. */\nexport function useRootNavigation() {\n return store.navigationRef.current;\n}\n\n/** @return the root `<NavigationContainer />` ref for the app. The `ref.current` may be `null` if the `<NavigationContainer />` hasn't mounted yet. */\nexport function useNavigationContainerRef() {\n return store.navigationRef;\n}\n\nexport function useRouter(): ExpoRouter.Router {\n return React.useMemo(\n () => ({\n push: store.push,\n dismiss: store.dismiss,\n dismissAll: store.dismissAll,\n canDismiss: store.canDismiss,\n back: store.goBack,\n replace: store.replace,\n setParams: store.setParams,\n canGoBack: store.canGoBack,\n navigate: store.navigate,\n // TODO(EvanBacon): add `reload`\n }),\n []\n );\n}\n\n/**\n * @private\n * @returns the current global pathname with query params attached. This may change in the future to include the hostname from a predefined universal link, i.e. `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`\n */\nexport function useUnstableGlobalHref(): string {\n return useStoreRouteInfo().unstable_globalHref;\n}\n\n/**\n * Get a list of selected file segments for the currently selected route. Segments are not normalized, so they will be the same as the file path. e.g. /[id]?id=normal -> [\"[id]\"]\n *\n * `useSegments` can be typed using an abstract.\n * Consider the following file structure, and strictly typed `useSegments` function:\n *\n * ```md\n * - app\n * - [user]\n * - index.js\n * - followers.js\n * - settings.js\n * ```\n * This can be strictly typed using the following abstract:\n *\n * ```ts\n * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()\n * ```\n */\nexport function useSegments<TSegments extends string[] = string[]>(): TSegments {\n return useStoreRouteInfo().segments as TSegments;\n}\n\n/** @returns global selected pathname without query parameters. */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * Get the globally selected query parameters, including dynamic path segments. This function will update even when the route is not focused.\n * Useful for analytics or other background operations that don't draw to the screen.\n *\n * When querying search params in a stack, opt-towards using `useLocalSearchParams` as these will only\n * update when the route is focused.\n *\n * @see `useLocalSearchParams`\n */\nexport function useGlobalSearchParams<\n TParams extends SearchParams = SearchParams,\n>(): Partial<TParams> {\n return useStoreRouteInfo().params as Partial<TParams>;\n}\n\n/**\n * Returns the URL search parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: \"bar\" }`.\n * This is useful for stacks where you may push a new screen that changes the query parameters.\n *\n * To observe updates even when the invoking route is not focused, use `useGlobalSearchParams()`.\n */\nexport function useLocalSearchParams<\n TParams extends SearchParams = SearchParams,\n>(): Partial<TParams> {\n const params = React.useContext(NavigationRouteContext)?.params ?? {};\n return Object.fromEntries(\n Object.entries(params).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [\n key,\n value.map((v) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n }),\n ];\n } else {\n try {\n return [key, decodeURIComponent(value as string)];\n } catch {\n return [key, value];\n }\n }\n })\n ) as Partial<TParams>;\n}\n"]}
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAkE;AAClE,kD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AAC;AAFD,kCAEC;AAED;;;;;;;;GAQG;AACH,SAAgB,qBAAqB;IAGnC,OAAO,IAAA,gCAAiB,GAAE,CAAC,MAA0B,CAAC;AACxD,CAAC;AAJD,sDAIC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB;IAGlC,MAAM,MAAM,GAAG,eAAK,CAAC,UAAU,CAAC,+BAAsB,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;IACtE,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,OAAO;gBACL,GAAG;gBACH,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;oBACd,IAAI;wBACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC;qBAC9B;oBAAC,MAAM;wBACN,OAAO,CAAC,CAAC;qBACV;gBACH,CAAC,CAAC;aACH,CAAC;SACH;aAAM;YACL,IAAI;gBACF,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAe,CAAC,CAAC,CAAC;aACnD;YAAC,MAAM;gBACN,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC,CAAC,CACiB,CAAC;AACxB,CAAC;AA1BD,oDA0BC","sourcesContent":["import { NavigationRouteContext } from '@react-navigation/native';\nimport React from 'react';\n\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { ExpoRouter } from '../types/expo-router';\n\ntype SearchParams = Record<string, string | string[]>;\n\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/** @deprecated use `useNavigationContainerRef()` instead, which returns a React ref. */\nexport function useRootNavigation() {\n return store.navigationRef.current;\n}\n\n/** @return the root `<NavigationContainer />` ref for the app. The `ref.current` may be `null` if the `<NavigationContainer />` hasn't mounted yet. */\nexport function useNavigationContainerRef() {\n return store.navigationRef;\n}\n\nexport function useRouter(): ExpoRouter.Router {\n return React.useMemo(\n () => ({\n push: store.push,\n dismiss: store.dismiss,\n dismissAll: store.dismissAll,\n canDismiss: store.canDismiss,\n back: store.goBack,\n replace: store.replace,\n setParams: store.setParams,\n canGoBack: store.canGoBack,\n navigate: store.navigate,\n // TODO(EvanBacon): add `reload`\n }),\n []\n );\n}\n\n/**\n * @private\n * @returns the current global pathname with query params attached. This may change in the future to include the hostname from a predefined universal link, i.e. `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`\n */\nexport function useUnstableGlobalHref(): string {\n return useStoreRouteInfo().unstable_globalHref;\n}\n\n/**\n * Get a list of selected file segments for the currently selected route. Segments are not normalized, so they will be the same as the file path. e.g. /[id]?id=normal -> [\"[id]\"]\n *\n * `useSegments` can be typed using an abstract.\n * Consider the following file structure, and strictly typed `useSegments` function:\n *\n * ```md\n * - app\n * - [user]\n * - index.js\n * - followers.js\n * - settings.js\n * ```\n * This can be strictly typed using the following abstract:\n *\n * ```ts\n * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()\n * ```\n */\nexport function useSegments<TSegments extends string[] = string[]>(): TSegments {\n return useStoreRouteInfo().segments as TSegments;\n}\n\n/** @returns global selected pathname without query parameters. */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * Get the globally selected query parameters, including dynamic path segments. This function will update even when the route is not focused.\n * Useful for analytics or other background operations that don't draw to the screen.\n *\n * When querying search params in a stack, opt-towards using `useLocalSearchParams` as these will only\n * update when the route is focused.\n *\n * @see `useLocalSearchParams`\n */\nexport function useGlobalSearchParams<\n TParams extends SearchParams = SearchParams,\n>(): Partial<TParams> {\n return useStoreRouteInfo().params as Partial<TParams>;\n}\n\n/**\n * Returns the URL parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: \"bar\" }`.\n * This is useful for stacks where you may push a new screen that changes the query parameters.\n * For dynamic routes, both the route parameters and the search parameters are returned.\n *\n * To observe updates even when the invoking route is not focused, use `useGlobalSearchParams()`.\n */\nexport function useLocalSearchParams<\n TParams extends SearchParams = SearchParams,\n>(): Partial<TParams> {\n const params = React.useContext(NavigationRouteContext)?.params ?? {};\n return Object.fromEntries(\n Object.entries(params).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [\n key,\n value.map((v) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n }),\n ];\n } else {\n try {\n return [key, decodeURIComponent(value as string)];\n } catch {\n return [key, value];\n }\n }\n })\n ) as Partial<TParams>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "3.5.16",
3
+ "version": "3.5.17",
4
4
  "description": "Expo Router is a file-based router for React Native and web applications.",
5
5
  "author": "650 Industries, Inc.",
6
6
  "license": "MIT",
@@ -102,5 +102,5 @@
102
102
  "react-native-helmet-async": "2.0.4",
103
103
  "schema-utils": "^4.0.1"
104
104
  },
105
- "gitHead": "2893e9cba95261919532de0675468c601b87b017"
105
+ "gitHead": "09b2d97bbc0f70f7c811ff9b6c9ad8808c5ad84b"
106
106
  }
@@ -301,8 +301,9 @@ export namespace ExpoRouter {
301
301
  type useRouter = typeof useRouter;
302
302
 
303
303
  /**
304
- * Returns the URL search parameters for the contextually focused route. e.g. \`/acme?foo=bar\` -> \`{ foo: "bar" }\`.
304
+ * Returns the URL parameters for the contextually focused route. e.g. \`/acme?foo=bar\` -> \`{ foo: "bar" }\`.
305
305
  * This is useful for stacks where you may push a new screen that changes the query parameters.
306
+ * For dynamic routes, both the route parameters and the search parameters are returned.
306
307
  *
307
308
  * To observe updates even when the invoking route is not focused, use \`useGlobalSearchParams()\`.
308
309
  * @see \`useGlobalSearchParams\`
@@ -318,10 +319,10 @@ export namespace ExpoRouter {
318
319
  type useSearchParams = typeof useSearchParams;
319
320
 
320
321
  /**
321
- * Get the globally selected query parameters, including dynamic path segments. This function will update even when the route is not focused.
322
+ * Get the globally selected URL parameters, including search parameters and dynamic path segments as route parameters. This function will update even when the route is not focused.
322
323
  * Useful for analytics or other background operations that don't draw to the screen.
323
324
  *
324
- * When querying search params in a stack, opt-towards using \`useLocalSearchParams\` as these will only
325
+ * When querying URL params in a stack, opt-towards using \`useLocalSearchParams\` as these will only
325
326
  * update when the route is focused.
326
327
  *
327
328
  * @see \`useLocalSearchParams\`