expo-router 2.0.9 → 2.0.11

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":"getRoutes.d.ts","sourceRoot":"","sources":["../src/getRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAW5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG;IACnE,yBAAyB;IACzB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,8CAA8C;IAC9C,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ,CA+C5D;AAyBD,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,GACX,iBAAiB,GAAG,IAAI,CAK1B;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,CAMlE;AAsND;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,QAiBxD;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CACvB,aAAa,EAAE,cAAc,EAC7B,OAAO,CAAC,EAAE,OAAO,GAChB,SAAS,GAAG,IAAI,CAclB;AAED,wBAAsB,cAAc,CAClC,aAAa,EAAE,cAAc,EAC7B,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,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAM,OAI7C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,QAsDrE"}
1
+ {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAe,MAAM,cAAc,CAAC;AAGjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAUlD,wBAAgB,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,QAEhD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,QAEnD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,QAGvC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAUpD;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,WAAW,EACjB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAM,OAI7C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,QAkErE"}
@@ -1,5 +1,3 @@
1
1
  import "@testing-library/jest-native/extend-expect";
2
- export declare const initialUrlRef: {
3
- value: string | Promise<string>;
4
- };
2
+ export declare function setInitialUrl(value: string): void;
5
3
  //# sourceMappingURL=mocks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,4CAA4C,CAAC;AAgBpD,eAAO,MAAM,aAAa,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAE5D,CAAC"}
1
+ {"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,4CAA4C,CAAC;AAkBpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,QAE1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "main": "src/index.tsx",
5
5
  "types": "build/index.d.ts",
6
6
  "files": [
@@ -105,12 +105,12 @@
105
105
  },
106
106
  "dependencies": {
107
107
  "@bacons/react-views": "^1.1.3",
108
- "@expo/metro-runtime": "2.2.11",
108
+ "@expo/metro-runtime": "2.2.13",
109
109
  "@radix-ui/react-slot": "1.0.1",
110
110
  "@react-navigation/bottom-tabs": "~6.5.7",
111
111
  "@react-navigation/native": "~6.1.6",
112
112
  "@react-navigation/native-stack": "~6.9.12",
113
- "expo-head": "0.0.15",
113
+ "expo-head": "0.0.17",
114
114
  "expo-splash-screen": "~0.20.2",
115
115
  "query-string": "7.1.3",
116
116
  "react-helmet-async": "^1.3.0",
package/src/getRoutes.ts CHANGED
@@ -169,21 +169,6 @@ function applyDefaultInitialRouteName(node: RouteNode): RouteNode {
169
169
  };
170
170
  }
171
171
 
172
- function cloneGroupRoute(
173
- node: RouteNode,
174
- { name: nextName }: { name: string }
175
- ): RouteNode {
176
- const groupName = `(${nextName})`;
177
- const parts = node.contextKey.split("/");
178
- parts[parts.length - 2] = groupName;
179
-
180
- return {
181
- ...node,
182
- route: groupName,
183
- contextKey: parts.join("/"),
184
- };
185
- }
186
-
187
172
  function folderNodeToRouteNode({
188
173
  name,
189
174
  children,
@@ -212,25 +197,8 @@ function fileNodeToRouteNode(tree: TreeNode): RouteNode[] | null {
212
197
 
213
198
  const dynamic = generateDynamic(name);
214
199
 
215
- const groupName = matchGroupName(name);
216
- const multiGroup = groupName?.includes(",");
217
-
218
- const clones = multiGroup
219
- ? groupName!.split(",").map((v) => ({ name: v.trim() }))
220
- : null;
221
-
222
- // Assert duplicates:
223
- if (clones) {
224
- const names = new Set<string>();
225
- for (const clone of clones) {
226
- if (names.has(clone.name)) {
227
- throw new Error(
228
- `Array syntax cannot contain duplicate group name "${clone.name}" in "${node.contextKey}".`
229
- );
230
- }
231
- names.add(clone.name);
232
- }
233
- }
200
+ const clones = extrapolateGroupRoutes(name, node.contextKey);
201
+ clones.delete(name);
234
202
 
235
203
  const output = {
236
204
  loadRoute: node.loadRoute,
@@ -240,9 +208,13 @@ function fileNodeToRouteNode(tree: TreeNode): RouteNode[] | null {
240
208
  dynamic,
241
209
  };
242
210
 
243
- if (Array.isArray(clones)) {
244
- return clones.map((clone) =>
245
- applyDefaultInitialRouteName(cloneGroupRoute({ ...output }, clone))
211
+ if (clones.size) {
212
+ return [...clones].map((clone) =>
213
+ applyDefaultInitialRouteName({
214
+ ...output,
215
+ contextKey: node.contextKey.replace(output.route, clone),
216
+ route: clone,
217
+ })
246
218
  );
247
219
  }
248
220
 
@@ -257,6 +229,43 @@ function fileNodeToRouteNode(tree: TreeNode): RouteNode[] | null {
257
229
  ];
258
230
  }
259
231
 
232
+ function extrapolateGroupRoutes(
233
+ route: string,
234
+ contextKey: string,
235
+ routes: Set<string> = new Set()
236
+ ): Set<string> {
237
+ const match = matchGroupName(route);
238
+
239
+ if (!match) {
240
+ routes.add(route);
241
+ return routes;
242
+ }
243
+
244
+ const groups = match?.split(",");
245
+ const groupsSet = new Set(groups);
246
+
247
+ if (groupsSet.size !== groups.length) {
248
+ throw new Error(
249
+ `Array syntax cannot contain duplicate group name "${groups}" in "${contextKey}".`
250
+ );
251
+ }
252
+
253
+ if (groups.length === 1) {
254
+ routes.add(route);
255
+ return routes;
256
+ }
257
+
258
+ for (const group of groups) {
259
+ extrapolateGroupRoutes(
260
+ route.replace(match, group.trim()),
261
+ contextKey,
262
+ routes
263
+ );
264
+ }
265
+
266
+ return routes;
267
+ }
268
+
260
269
  function treeNodeToRouteNode(tree: TreeNode): RouteNode[] | null {
261
270
  if (tree.node) {
262
271
  return fileNodeToRouteNode(tree);
@@ -78,16 +78,28 @@ export function linkTo(this: RouterStore, href: string, event?: string) {
78
78
  const rootState = navigationRef.getRootState();
79
79
 
80
80
  if (href.startsWith(".")) {
81
- let base =
82
- this.linking.getPathFromState?.(rootState, {
83
- screens: [],
84
- preserveGroups: true,
85
- }) ?? "";
86
-
87
- if (base && !base.endsWith("/")) {
88
- base += "/..";
89
- }
90
- href = resolve(base, href);
81
+ const base =
82
+ this.routeInfo?.segments
83
+ ?.map((segment) => {
84
+ if (!segment.startsWith("[")) return segment;
85
+
86
+ if (segment.startsWith("[...")) {
87
+ segment = segment.slice(4, -1);
88
+ const params = this.routeInfo?.params?.[segment];
89
+ if (Array.isArray(params)) {
90
+ return params.join("/");
91
+ } else {
92
+ return params?.split(",")?.join("/") ?? "";
93
+ }
94
+ } else {
95
+ segment = segment.slice(1, -1);
96
+ return this.routeInfo?.params?.[segment];
97
+ }
98
+ })
99
+ .filter(Boolean)
100
+ .join("/") ?? "/";
101
+
102
+ href = resolve(base + "/..", href);
91
103
  }
92
104
 
93
105
  const state = this.linking.getStateFromPath!(href, this.linking.config);
package/src/matchers.tsx CHANGED
@@ -12,7 +12,7 @@ export function matchDeepDynamicRouteName(name: string): string | undefined {
12
12
 
13
13
  /** Match `(page)` -> `page` */
14
14
  export function matchGroupName(name: string): string | undefined {
15
- return name.match(/^\(([^/]+?)\)$/)?.[1];
15
+ return name.match(/^(?:[^\\(\\)])*?\(([^\\/]+)\).*?$/)?.[1];
16
16
  }
17
17
 
18
18
  export function getNameFromFilePath(name: string): string {
@@ -15,7 +15,7 @@ import {
15
15
  requireContext,
16
16
  requireContextWithOverrides,
17
17
  } from "./context-stubs";
18
- import { initialUrlRef } from "./mocks";
18
+ import { setInitialUrl } from "./mocks";
19
19
 
20
20
  // re-export everything
21
21
  export * from "@testing-library/react-native";
@@ -60,7 +60,8 @@ export function renderRouter(
60
60
  let ctx: RequireContext;
61
61
 
62
62
  // Reset the initial URL
63
- initialUrlRef.value = initialUrl as any;
63
+
64
+ setInitialUrl(initialUrl);
64
65
 
65
66
  // Force the render to be synchronous
66
67
  process.env.EXPO_ROUTER_IMPORT_MODE_WEB = "sync";
@@ -14,9 +14,11 @@ jest.mock("react-native-reanimated", () => {
14
14
  // Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
15
15
  jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
16
16
 
17
- export const initialUrlRef: { value: string | Promise<string> } = {
18
- value: "",
19
- };
17
+ let mockInitialUrl: string | Promise<string> = "";
18
+
19
+ export function setInitialUrl(value: string) {
20
+ mockInitialUrl = value;
21
+ }
20
22
 
21
23
  jest.mock("expo-linking", () => {
22
24
  const module: typeof import("expo-linking") = {
@@ -31,7 +33,7 @@ jest.mock("expo-linking", () => {
31
33
  return { remove() {} } as any;
32
34
  },
33
35
  async getInitialURL() {
34
- return initialUrlRef.value;
36
+ return mockInitialUrl;
35
37
  },
36
38
  };
37
39