expo-router 2.0.13 → 2.0.15

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.
@@ -3,4 +3,6 @@
3
3
  * NOTE: Additional strictness added to ensure URLs sent in query parameters for in-app navigation are not matched.
4
4
  */
5
5
  export declare function hasUrlProtocolPrefix(href: string): boolean;
6
+ export declare function isWellKnownUri(href: string): boolean;
7
+ export declare function shouldLinkExternally(href: string): boolean;
6
8
  //# sourceMappingURL=url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-router",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "main": "src/index.tsx",
5
5
  "types": "build/index.d.ts",
6
6
  "license": "MIT",
@@ -64,10 +64,6 @@
64
64
  "peerDependencies": {
65
65
  "@react-navigation/drawer": "^6.5.8",
66
66
  "expo": "^49.0.0",
67
- "expo-constants": "*",
68
- "expo-linking": "*",
69
- "expo-status-bar": "*",
70
- "metro": "~0.76.7",
71
67
  "react-native-gesture-handler": "*",
72
68
  "react-native-reanimated": "*",
73
69
  "react-native-safe-area-context": "*",
@@ -106,12 +102,12 @@
106
102
  },
107
103
  "dependencies": {
108
104
  "@bacons/react-views": "^1.1.3",
109
- "@expo/metro-runtime": "2.2.15",
105
+ "@expo/metro-runtime": "2.2.16",
110
106
  "@radix-ui/react-slot": "1.0.1",
111
107
  "@react-navigation/bottom-tabs": "~6.5.7",
112
108
  "@react-navigation/native": "~6.1.6",
113
109
  "@react-navigation/native-stack": "~6.9.12",
114
- "expo-head": "0.0.19",
110
+ "expo-head": "0.0.20",
115
111
  "expo-splash-screen": "~0.20.2",
116
112
  "query-string": "7.1.3",
117
113
  "react-helmet-async": "^1.3.0",
@@ -7,7 +7,7 @@ import * as Linking from "expo-linking";
7
7
  import { ResultState } from "../fork/getStateFromPath";
8
8
  import { Href, resolveHref } from "../link/href";
9
9
  import { resolve } from "../link/path";
10
- import { hasUrlProtocolPrefix } from "../utils/url";
10
+ import { shouldLinkExternally } from "../utils/url";
11
11
  import type { RouterStore } from "./router-store";
12
12
 
13
13
  function assertIsReady(store: RouterStore) {
@@ -52,7 +52,7 @@ export function setParams(
52
52
  }
53
53
 
54
54
  export function linkTo(this: RouterStore, href: string, event?: string) {
55
- if (hasUrlProtocolPrefix(href)) {
55
+ if (shouldLinkExternally(href)) {
56
56
  Linking.openURL(href);
57
57
  return;
58
58
  }
@@ -135,7 +135,7 @@ function rewriteNavigationStateToParams(
135
135
  ) {
136
136
  if (!state) return params;
137
137
  // We Should always have at least one route in the state
138
- const lastRoute = state.routes.at(-1)!;
138
+ const lastRoute = state.routes[state.routes.length - 1]!;
139
139
  params.screen = lastRoute.name;
140
140
  // Weirdly, this always needs to be an object. If it's undefined, it won't work.
141
141
  params.params = lastRoute.params
@@ -167,7 +167,7 @@ function getNavigateReplaceAction(
167
167
  lastNavigatorSupportingReplace: NavigationState = parentState
168
168
  ): NavigationAction {
169
169
  // We should always have at least one route in the state
170
- const route = state.routes.at(-1)!;
170
+ const route = state.routes[state.routes.length - 1]!;
171
171
 
172
172
  // Only these navigators support replace
173
173
  if (parentState.type === "stack" || parentState.type === "tab") {
package/src/utils/url.ts CHANGED
@@ -5,3 +5,19 @@
5
5
  export function hasUrlProtocolPrefix(href: string): boolean {
6
6
  return /^[\w\d_+.-]+:\/\//.test(href);
7
7
  }
8
+
9
+ export function isWellKnownUri(href: string): boolean {
10
+ // This is a hack and we should change this to work like the web in the future where we have full confidence in the
11
+ // ability to match URLs and send anything unmatched to the OS. The main difference between this and `hasUrlProtocolPrefix` is
12
+ // that we don't require `//`, e.g. `mailto:` is valid and common, and `mailto://bacon` is invalid.
13
+ return /^(https?|mailto|tel|sms|geo|maps|market|itmss?|itms-apps|content|file):/.test(
14
+ href
15
+ );
16
+ }
17
+
18
+ export function shouldLinkExternally(href: string): boolean {
19
+ // Cheap check first to avoid regex if the href is not a path fragment.
20
+ return (
21
+ !/^[./]/.test(href) && (hasUrlProtocolPrefix(href) || isWellKnownUri(href))
22
+ );
23
+ }