expo-router 4.0.0-preview.11 → 4.0.0-preview.13
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/build/ExpoRoot.js +2 -2
- package/build/ExpoRoot.js.map +1 -1
- package/build/exports.d.ts +1 -1
- package/build/exports.d.ts.map +1 -1
- package/build/exports.js +24 -2
- package/build/exports.js.map +1 -1
- package/build/fast-refresh.d.ts.map +1 -1
- package/build/fast-refresh.js.map +1 -1
- package/build/getRoutesCore.d.ts +1 -0
- package/build/getRoutesCore.d.ts.map +1 -1
- package/build/getRoutesCore.js +3 -1
- package/build/getRoutesCore.js.map +1 -1
- package/build/global-state/router-store.d.ts.map +1 -1
- package/build/global-state/router-store.js +1 -2
- package/build/global-state/router-store.js.map +1 -1
- package/build/head/url.d.ts +1 -0
- package/build/head/url.d.ts.map +1 -1
- package/build/head/url.js +21 -4
- package/build/head/url.js.map +1 -1
- package/build/hooks.d.ts +90 -38
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +46 -39
- package/build/hooks.js.map +1 -1
- package/build/imperative-api.d.ts +58 -15
- package/build/imperative-api.d.ts.map +1 -1
- package/build/imperative-api.js.map +1 -1
- package/build/layouts/Drawer.d.ts +2 -142
- package/build/layouts/Drawer.d.ts.map +1 -1
- package/build/layouts/Drawer.js +8 -5
- package/build/layouts/Drawer.js.map +1 -1
- package/build/layouts/DrawerClient.d.ts +144 -0
- package/build/layouts/DrawerClient.d.ts.map +1 -0
- package/build/layouts/DrawerClient.js +10 -0
- package/build/layouts/DrawerClient.js.map +1 -0
- package/build/layouts/Stack.d.ts +2 -126
- package/build/layouts/Stack.d.ts.map +1 -1
- package/build/layouts/Stack.js +8 -6
- package/build/layouts/Stack.js.map +1 -1
- package/build/layouts/StackClient.d.ts +128 -0
- package/build/layouts/StackClient.d.ts.map +1 -0
- package/build/layouts/StackClient.js +10 -0
- package/build/layouts/StackClient.js.map +1 -0
- package/build/layouts/Tabs.d.ts +2 -134
- package/build/layouts/Tabs.d.ts.map +1 -1
- package/build/layouts/Tabs.js +5 -37
- package/build/layouts/Tabs.js.map +1 -1
- package/build/layouts/TabsClient.d.ts +136 -0
- package/build/layouts/TabsClient.d.ts.map +1 -0
- package/build/layouts/TabsClient.js +44 -0
- package/build/layouts/TabsClient.js.map +1 -0
- package/build/layouts/withLayoutContext.d.ts +4 -1
- package/build/layouts/withLayoutContext.d.ts.map +1 -1
- package/build/layouts/withLayoutContext.js +4 -1
- package/build/layouts/withLayoutContext.js.map +1 -1
- package/build/link/Link.d.ts +48 -4
- package/build/link/Link.d.ts.map +1 -1
- package/build/link/Link.js +47 -3
- package/build/link/Link.js.map +1 -1
- package/build/link/href.d.ts +1 -1
- package/build/link/href.d.ts.map +1 -1
- package/build/link/href.js.map +1 -1
- package/build/link/useLinkHooks.d.ts +122 -29
- package/build/link/useLinkHooks.d.ts.map +1 -1
- package/build/link/useLinkHooks.js.map +1 -1
- package/build/renderRootComponent.d.ts.map +1 -1
- package/build/renderRootComponent.js +1 -2
- package/build/renderRootComponent.js.map +1 -1
- package/build/rsc/exports.d.ts +3 -1
- package/build/rsc/exports.d.ts.map +1 -1
- package/build/rsc/exports.js +3 -1
- package/build/rsc/exports.js.map +1 -1
- package/build/rsc/middleware.d.ts +1 -1
- package/build/rsc/middleware.d.ts.map +1 -1
- package/build/rsc/middleware.js +2 -1
- package/build/rsc/middleware.js.map +1 -1
- package/build/rsc/router/client.d.ts +2 -2
- package/build/rsc/router/client.d.ts.map +1 -1
- package/build/rsc/router/client.js.map +1 -1
- package/build/rsc/router/host.d.ts.map +1 -1
- package/build/rsc/router/host.js +20 -15
- package/build/rsc/router/host.js.map +1 -1
- package/build/rsc/rsc-renderer.d.ts +1 -1
- package/build/rsc/rsc-renderer.d.ts.map +1 -1
- package/build/rsc/rsc-renderer.js +1 -1
- package/build/rsc/rsc-renderer.js.map +1 -1
- package/build/rsc/server.d.ts +3 -0
- package/build/rsc/server.d.ts.map +1 -1
- package/build/rsc/server.js +19 -1
- package/build/rsc/server.js.map +1 -1
- package/build/testing-library/context-stubs.d.ts.map +1 -1
- package/build/testing-library/context-stubs.js +3 -1
- package/build/testing-library/context-stubs.js.map +1 -1
- package/build/testing-library/mocks.js +14 -13
- package/build/testing-library/mocks.js.map +1 -1
- package/build/typed-routes/generate.d.ts +5 -1
- package/build/typed-routes/generate.d.ts.map +1 -1
- package/build/typed-routes/generate.js +129 -64
- package/build/typed-routes/generate.js.map +1 -1
- package/build/typed-routes/index.d.ts +5 -0
- package/build/typed-routes/index.d.ts.map +1 -1
- package/build/typed-routes/index.js +8 -3
- package/build/typed-routes/index.js.map +1 -1
- package/build/typed-routes/testSetup.d.ts +1 -1
- package/build/typed-routes/testSetup.d.ts.map +1 -1
- package/build/typed-routes/testSetup.js +29 -17
- package/build/typed-routes/testSetup.js.map +1 -1
- package/build/typed-routes/types.d.ts +43 -145
- package/build/typed-routes/types.d.ts.map +1 -1
- package/build/typed-routes/types.js.map +1 -1
- package/build/types.d.ts +33 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/ui/TabContext.d.ts +158 -1
- package/build/ui/TabContext.d.ts.map +1 -1
- package/build/ui/TabContext.js +25 -1
- package/build/ui/TabContext.js.map +1 -1
- package/build/ui/TabList.d.ts +17 -1
- package/build/ui/TabList.d.ts.map +1 -1
- package/build/ui/TabList.js +16 -0
- package/build/ui/TabList.js.map +1 -1
- package/build/ui/TabSlot.d.ts +55 -5
- package/build/ui/TabSlot.d.ts.map +1 -1
- package/build/ui/TabSlot.js +38 -14
- package/build/ui/TabSlot.js.map +1 -1
- package/build/ui/TabTrigger.d.ts +65 -70
- package/build/ui/TabTrigger.d.ts.map +1 -1
- package/build/ui/TabTrigger.js +25 -1
- package/build/ui/TabTrigger.js.map +1 -1
- package/build/ui/Tabs.d.ts +89 -132
- package/build/ui/Tabs.d.ts.map +1 -1
- package/build/ui/Tabs.js +53 -8
- package/build/ui/Tabs.js.map +1 -1
- package/build/ui/common.d.ts +3 -3
- package/build/ui/common.d.ts.map +1 -1
- package/build/ui/common.js.map +1 -1
- package/build/useFocusEffect.d.ts +15 -6
- package/build/useFocusEffect.d.ts.map +1 -1
- package/build/useFocusEffect.js +15 -6
- package/build/useFocusEffect.js.map +1 -1
- package/build/useNavigation.d.ts +11 -5
- package/build/useNavigation.d.ts.map +1 -1
- package/build/useNavigation.js +11 -5
- package/build/useNavigation.js.map +1 -1
- package/build/utils/splash.d.ts +6 -0
- package/build/utils/splash.d.ts.map +1 -0
- package/build/utils/splash.js +51 -0
- package/build/utils/splash.js.map +1 -0
- package/build/views/Navigator.d.ts +6 -5
- package/build/views/Navigator.d.ts.map +1 -1
- package/build/views/Navigator.js +6 -5
- package/build/views/Navigator.js.map +1 -1
- package/build/views/Splash.d.ts +1 -1
- package/build/views/Splash.d.ts.map +1 -1
- package/build/views/Splash.js +3 -13
- package/build/views/Splash.js.map +1 -1
- package/build/views/Try.d.ts +1 -1
- package/build/views/Try.d.ts.map +1 -1
- package/build/views/Try.js +1 -1
- package/build/views/Try.js.map +1 -1
- package/entry-classic.js +0 -6
- package/package.json +3 -5
- package/plugin/build/index.d.ts +2 -0
- package/plugin/options.json +74 -73
- package/rsc/entry.js +0 -6
- package/rsc/headers.d.ts +3 -0
- package/rsc/headers.js +5 -0
- package/build/rsc/runtime.d.ts +0 -9
- package/build/rsc/runtime.d.ts.map +0 -1
- package/build/rsc/runtime.js +0 -36
- package/build/rsc/runtime.js.map +0 -1
- package/virtual-client-boundaries.js +0 -1
package/build/hooks.d.ts
CHANGED
|
@@ -1,20 +1,60 @@
|
|
|
1
1
|
import { Router } from './imperative-api';
|
|
2
|
-
import { RouteParams, RouteSegments,
|
|
3
|
-
|
|
2
|
+
import { RouteParams, RouteSegments, UnknownOutputParams, Route } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the [navigation state](https://reactnavigation.org/docs/navigation-state/)
|
|
5
|
+
* of the navigator which contains the current screen.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useRootNavigationState } from 'expo-router';
|
|
10
|
+
*
|
|
11
|
+
* export default function Route() {
|
|
12
|
+
* const { routes } = useRootNavigationState();
|
|
13
|
+
*
|
|
14
|
+
* return <Text>{routes[0].name}</Text>;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
export declare function useRootNavigationState(): any;
|
|
5
19
|
export declare function useRouteInfo(): import("./LocationProvider").UrlObject;
|
|
6
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use [`useNavigationContainerRef`](#usenavigationcontainerref) instead,
|
|
22
|
+
* which returns a React `ref`.
|
|
23
|
+
*/
|
|
7
24
|
export declare function useRootNavigation(): import("@react-navigation/core").NavigationContainerRef<ReactNavigation.RootParamList> | null;
|
|
8
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* @return The root `<NavigationContainer />` ref for the app. The `ref.current` may be `null`
|
|
27
|
+
* if the `<NavigationContainer />` hasn't mounted yet.
|
|
28
|
+
*/
|
|
9
29
|
export declare function useNavigationContainerRef(): import("@react-navigation/core").NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* Returns the [Router](#router) object for imperative navigation.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
*```tsx
|
|
36
|
+
* import { useRouter } from 'expo-router';
|
|
37
|
+
* import { Text } from 'react-native';
|
|
38
|
+
*
|
|
39
|
+
* export default function Route() {
|
|
40
|
+
* const router = useRouter();
|
|
41
|
+
*
|
|
42
|
+
* return (
|
|
43
|
+
* <Text onPress={() => router.push('/home')}>Go Home</Text>
|
|
44
|
+
* );
|
|
45
|
+
*}
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
10
48
|
export declare function useRouter(): Router;
|
|
11
49
|
/**
|
|
12
50
|
* @private
|
|
13
|
-
* @returns The current global pathname with query params attached. This may change in the future to include the hostname
|
|
51
|
+
* @returns The current global pathname with query params attached. This may change in the future to include the hostname
|
|
52
|
+
* from a predefined universal link. For example, `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`.
|
|
14
53
|
*/
|
|
15
54
|
export declare function useUnstableGlobalHref(): string;
|
|
16
55
|
/**
|
|
17
|
-
*
|
|
56
|
+
* Returns a list of selected file segments for the currently selected route. Segments are not normalized,
|
|
57
|
+
* so they will be the same as the file path. For example, `/[id]?id=normal` becomes `["[id]"]`.
|
|
18
58
|
*
|
|
19
59
|
* @example
|
|
20
60
|
* ```tsx app/profile/[user].tsx
|
|
@@ -30,26 +70,28 @@ export declare function useUnstableGlobalHref(): string;
|
|
|
30
70
|
* ```
|
|
31
71
|
*
|
|
32
72
|
*
|
|
33
|
-
* `useSegments` can be typed using an abstract. Consider the following file structure
|
|
73
|
+
* `useSegments` can be typed using an abstract. Consider the following file structure:
|
|
34
74
|
*
|
|
35
75
|
* ```md
|
|
36
76
|
* - app
|
|
37
77
|
* - [user]
|
|
38
|
-
* - index.
|
|
39
|
-
* - followers.
|
|
40
|
-
* - settings.
|
|
78
|
+
* - index.tsx
|
|
79
|
+
* - followers.tsx
|
|
80
|
+
* - settings.tsx
|
|
41
81
|
* ```
|
|
42
82
|
*
|
|
43
83
|
*
|
|
44
|
-
* This can be strictly typed using the following abstract:
|
|
84
|
+
* This can be strictly typed using the following abstract with `useSegments` hook:
|
|
45
85
|
*
|
|
46
|
-
* ```
|
|
86
|
+
* ```tsx
|
|
47
87
|
* const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()
|
|
48
88
|
* ```
|
|
49
89
|
*/
|
|
50
|
-
export declare function useSegments<TSegments extends
|
|
90
|
+
export declare function useSegments<TSegments extends Route = Route>(): RouteSegments<TSegments>;
|
|
91
|
+
export declare function useSegments<TSegments extends RouteSegments<Route>>(): TSegments;
|
|
51
92
|
/**
|
|
52
|
-
*
|
|
93
|
+
* Returns the currently selected route location without search parameters. For example, `/acme?foo=bar` returns `/acme`.
|
|
94
|
+
* Segments will be normalized. For example, `/[id]?id=normal` becomes `/normal`.
|
|
53
95
|
*
|
|
54
96
|
* @example
|
|
55
97
|
* ```tsx app/profile/[user].tsx
|
|
@@ -57,7 +99,7 @@ export declare function useSegments<TSegments extends Routes | RouteSegments<Rou
|
|
|
57
99
|
* import { useSegments } from 'expo-router';
|
|
58
100
|
*
|
|
59
101
|
* export default function Route() {
|
|
60
|
-
* // segments = ["profile", "[user]"]
|
|
102
|
+
* // segments = ["profile", "[user]"]
|
|
61
103
|
* const segments = useSegments();
|
|
62
104
|
*
|
|
63
105
|
* return <Text>Hello</Text>;
|
|
@@ -66,20 +108,17 @@ export declare function useSegments<TSegments extends Routes | RouteSegments<Rou
|
|
|
66
108
|
*/
|
|
67
109
|
export declare function usePathname(): string;
|
|
68
110
|
/**
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Get the globally selected query parameters, including dynamic path segments. This function will update even when the route is not focused.
|
|
74
|
-
* Useful for analytics or other background operations that don't draw to the screen.
|
|
75
|
-
*
|
|
76
|
-
* When querying search params in a stack, opt-towards using [`useLocalSearchParams`](#uselocalsearchparams) as these will only update when the route is focused.
|
|
111
|
+
* Returns URL parameters for globally selected route, including dynamic path segments.
|
|
112
|
+
* This function updates even when the route is not focused. Useful for analytics or
|
|
113
|
+
* other background operations that don't draw to the screen.
|
|
77
114
|
*
|
|
78
115
|
* Route URL example: `acme://profile/baconbrix?extra=info`.
|
|
79
116
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
117
|
+
* When querying search params in a stack, opt-towards using
|
|
118
|
+
* [`useLocalSearchParams`](#uselocalsearchparams) because it will only update when the route is focused.
|
|
82
119
|
*
|
|
120
|
+
* > **Note:** For usage information, see
|
|
121
|
+
* [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).
|
|
83
122
|
*
|
|
84
123
|
* @example
|
|
85
124
|
* ```tsx app/profile/[user].tsx
|
|
@@ -89,28 +128,41 @@ export declare function useGlobalSearchParams<TParams extends SearchParams = Unk
|
|
|
89
128
|
* export default function Route() {
|
|
90
129
|
* // user=baconbrix & extra=info
|
|
91
130
|
* const { user, extra } = useGlobalSearchParams();
|
|
131
|
+
*
|
|
92
132
|
* return <Text>User: {user}</Text>;
|
|
93
133
|
* }
|
|
94
134
|
* ```
|
|
95
|
-
*
|
|
96
|
-
*/
|
|
97
|
-
export declare function useGlobalSearchParams<TRoute extends Routes, TParams extends SearchParams = UnknownOutputParams>(): RouteParams<TRoute, TParams>;
|
|
98
|
-
/**
|
|
99
|
-
* @hidden
|
|
100
135
|
*/
|
|
101
|
-
export declare function
|
|
136
|
+
export declare function useGlobalSearchParams<TParams extends UnknownOutputParams = UnknownOutputParams>(): TParams;
|
|
137
|
+
export declare function useGlobalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;
|
|
138
|
+
export declare function useGlobalSearchParams<TRoute extends Route, TParams extends UnknownOutputParams = UnknownOutputParams>(): RouteParams<TRoute> & TParams;
|
|
102
139
|
/**
|
|
103
|
-
* Returns the URL parameters for the contextually focused route.
|
|
104
|
-
*
|
|
105
|
-
* For dynamic routes, both the route parameters and the search parameters are returned.
|
|
140
|
+
* Returns the URL parameters for the contextually focused route. Useful for stacks where you may push a new screen
|
|
141
|
+
* that changes the query parameters. For dynamic routes, both the route parameters and the search parameters are returned.
|
|
106
142
|
*
|
|
107
|
-
*
|
|
143
|
+
* Route URL example: `acme://profile/baconbrix?extra=info`.
|
|
144
|
+
*
|
|
145
|
+
* To observe updates even when the invoking route is not focused, use [`useGlobalSearchParams`](#useglobalsearchparams).
|
|
146
|
+
*
|
|
147
|
+
* > **Note:** For usage information, see
|
|
148
|
+
* [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx app/profile/[user].tsx
|
|
152
|
+
* import { Text } from 'react-native';
|
|
153
|
+
* import { useLocalSearchParams } from 'expo-router';
|
|
108
154
|
*
|
|
109
|
-
*
|
|
155
|
+
* export default function Route() {
|
|
156
|
+
* // user=baconbrix & extra=info
|
|
157
|
+
* const { user, extra } = useLocalSearchParams();
|
|
158
|
+
*
|
|
159
|
+
* return <Text>User: {user}</Text>;
|
|
160
|
+
* }
|
|
110
161
|
*/
|
|
111
|
-
export declare function useLocalSearchParams<
|
|
162
|
+
export declare function useLocalSearchParams<TParams extends UnknownOutputParams = UnknownOutputParams>(): TParams;
|
|
163
|
+
export declare function useLocalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;
|
|
164
|
+
export declare function useLocalSearchParams<TRoute extends Route, TParams extends UnknownOutputParams = UnknownOutputParams>(): RouteParams<TRoute> & TParams;
|
|
112
165
|
export declare function useSearchParams({ global }?: {
|
|
113
166
|
global?: boolean | undefined;
|
|
114
167
|
}): URLSearchParams;
|
|
115
|
-
export {};
|
|
116
168
|
//# sourceMappingURL=hooks.d.ts.map
|
package/build/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,QAErC;AAED,wBAAgB,YAAY,2CAE3B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,kGAEhC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,sGAExC;AAED;;;;;;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Params = exports.useGlobalSearch
|
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
9
|
const Route_1 = require("./Route");
|
|
10
10
|
const router_store_1 = require("./global-state/router-store");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the [navigation state](https://reactnavigation.org/docs/navigation-state/)
|
|
13
|
+
* of the navigator which contains the current screen.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { useRootNavigationState } from 'expo-router';
|
|
18
|
+
*
|
|
19
|
+
* export default function Route() {
|
|
20
|
+
* const { routes } = useRootNavigationState();
|
|
21
|
+
*
|
|
22
|
+
* return <Text>{routes[0].name}</Text>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
11
26
|
function useRootNavigationState() {
|
|
12
27
|
return (0, router_store_1.useStoreRootState)();
|
|
13
28
|
}
|
|
@@ -16,16 +31,40 @@ function useRouteInfo() {
|
|
|
16
31
|
return (0, router_store_1.useStoreRouteInfo)();
|
|
17
32
|
}
|
|
18
33
|
exports.useRouteInfo = useRouteInfo;
|
|
19
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use [`useNavigationContainerRef`](#usenavigationcontainerref) instead,
|
|
36
|
+
* which returns a React `ref`.
|
|
37
|
+
*/
|
|
20
38
|
function useRootNavigation() {
|
|
21
39
|
return router_store_1.store.navigationRef.current;
|
|
22
40
|
}
|
|
23
41
|
exports.useRootNavigation = useRootNavigation;
|
|
24
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* @return The root `<NavigationContainer />` ref for the app. The `ref.current` may be `null`
|
|
44
|
+
* if the `<NavigationContainer />` hasn't mounted yet.
|
|
45
|
+
*/
|
|
25
46
|
function useNavigationContainerRef() {
|
|
26
47
|
return router_store_1.store.navigationRef;
|
|
27
48
|
}
|
|
28
49
|
exports.useNavigationContainerRef = useNavigationContainerRef;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Returns the [Router](#router) object for imperative navigation.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
*```tsx
|
|
56
|
+
* import { useRouter } from 'expo-router';
|
|
57
|
+
* import { Text } from 'react-native';
|
|
58
|
+
*
|
|
59
|
+
* export default function Route() {
|
|
60
|
+
* const router = useRouter();
|
|
61
|
+
*
|
|
62
|
+
* return (
|
|
63
|
+
* <Text onPress={() => router.push('/home')}>Go Home</Text>
|
|
64
|
+
* );
|
|
65
|
+
*}
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
29
68
|
function useRouter() {
|
|
30
69
|
return react_1.default.useMemo(() => ({
|
|
31
70
|
push: router_store_1.store.push,
|
|
@@ -43,52 +82,20 @@ function useRouter() {
|
|
|
43
82
|
exports.useRouter = useRouter;
|
|
44
83
|
/**
|
|
45
84
|
* @private
|
|
46
|
-
* @returns The current global pathname with query params attached. This may change in the future to include the hostname
|
|
85
|
+
* @returns The current global pathname with query params attached. This may change in the future to include the hostname
|
|
86
|
+
* from a predefined universal link. For example, `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`.
|
|
47
87
|
*/
|
|
48
88
|
function useUnstableGlobalHref() {
|
|
49
89
|
return (0, router_store_1.useStoreRouteInfo)().unstable_globalHref;
|
|
50
90
|
}
|
|
51
91
|
exports.useUnstableGlobalHref = useUnstableGlobalHref;
|
|
52
|
-
/**
|
|
53
|
-
* 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. For example: `/[id]?id=normal -> ["[id]"]`.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```tsx app/profile/[user].tsx
|
|
57
|
-
* import { Text } from 'react-native';
|
|
58
|
-
* import { useSegments } from 'expo-router';
|
|
59
|
-
*
|
|
60
|
-
* export default function Route() {
|
|
61
|
-
* // segments = ["profile", "[user]"]
|
|
62
|
-
* const segments = useSegments();
|
|
63
|
-
*
|
|
64
|
-
* return <Text>Hello</Text>;
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* `useSegments` can be typed using an abstract. Consider the following file structure, and strictly typed `useSegments` function:
|
|
70
|
-
*
|
|
71
|
-
* ```md
|
|
72
|
-
* - app
|
|
73
|
-
* - [user]
|
|
74
|
-
* - index.js
|
|
75
|
-
* - followers.js
|
|
76
|
-
* - settings.js
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* This can be strictly typed using the following abstract:
|
|
81
|
-
*
|
|
82
|
-
* ```ts
|
|
83
|
-
* const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
92
|
function useSegments() {
|
|
87
93
|
return (0, router_store_1.useStoreRouteInfo)().segments;
|
|
88
94
|
}
|
|
89
95
|
exports.useSegments = useSegments;
|
|
90
96
|
/**
|
|
91
|
-
*
|
|
97
|
+
* Returns the currently selected route location without search parameters. For example, `/acme?foo=bar` returns `/acme`.
|
|
98
|
+
* Segments will be normalized. For example, `/[id]?id=normal` becomes `/normal`.
|
|
92
99
|
*
|
|
93
100
|
* @example
|
|
94
101
|
* ```tsx app/profile/[user].tsx
|
|
@@ -96,7 +103,7 @@ exports.useSegments = useSegments;
|
|
|
96
103
|
* import { useSegments } from 'expo-router';
|
|
97
104
|
*
|
|
98
105
|
* export default function Route() {
|
|
99
|
-
* // segments = ["profile", "[user]"]
|
|
106
|
+
* // segments = ["profile", "[user]"]
|
|
100
107
|
* const segments = useSegments();
|
|
101
108
|
*
|
|
102
109
|
* return <Text>Hello</Text>;
|
package/build/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAEb,kDAA0B;AAE1B,mCAAkD;AAClD,8DAA0F;AAK1F,SAAgB,sBAAsB;IACpC,OAAO,IAAA,gCAAiB,GAAE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oB,EAAE,CAAC;IACzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC9D,IAAI,MAAM,EAAE;YACV,IAAI,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;YAChC,IAAI,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;SACjC;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAtBD,0CAsBC;AAED,MAAM,uBAAwB,SAAQ,eAAe;IACnD,GAAG;QACD,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;CACF","sourcesContent":["'use client';\n\nimport React from 'react';\n\nimport { LocalRouteParamsContext } from './Route';\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { Router } from './imperative-api';\nimport { RouteParams, RouteSegments, Routes, UnknownOutputParams } from './types';\n\ntype SearchParams = Record<string, string | string[]>;\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/** @deprecated Use [`useNavigationContainerRef`](#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(): 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 reload: store.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. For example, `/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. For example: `/[id]?id=normal -> [\"[id]\"]`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n *\n *\n * `useSegments` can be typed using an abstract. 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 *\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<\n TSegments extends Routes | RouteSegments<Routes> = Routes,\n>(): TSegments extends string ? RouteSegments<TSegments> : TSegments {\n return useStoreRouteInfo().segments as TSegments extends string\n ? RouteSegments<TSegments>\n : TSegments;\n}\n\n/**\n * Global selected route location without search parameters. For example, `/acme?foo=bar` -> `/acme`. Segments will be normalized: `/[id]?id=normal` -> `/normal`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]</b>\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * @hidden\n */\nexport function useGlobalSearchParams<\n TParams extends SearchParams = UnknownOutputParams,\n>(): RouteParams<TParams>;\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`](#uselocalsearchparams) as these will only update when the route is focused.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * > **Note:** See [local versus global search parameters](/router/reference/search-parameters/#local-versus-global-search-parameters) for usage\n * > information.\n *\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useGlobalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useGlobalSearchParams();\n * return <Text>User: {user}</Text>;\n * }\n * ```\n *\n */\nexport function useGlobalSearchParams<\n TRoute extends Routes,\n TParams extends SearchParams = UnknownOutputParams,\n>(): RouteParams<TRoute, TParams>;\nexport function useGlobalSearchParams<\n TParams1 extends SearchParams | Routes = UnknownOutputParams,\n TParams2 extends SearchParams = UnknownOutputParams,\n>(): RouteParams<TParams1, TParams2> {\n return useStoreRouteInfo().params as RouteParams<TParams1, TParams2>;\n}\n\n/**\n * @hidden\n */\nexport function useLocalSearchParams<\n TParams extends SearchParams = UnknownOutputParams,\n>(): RouteParams<TParams>;\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 *\n * @see [`useGlobalSearchParams`](#useglobalsearchparams)\n */\nexport function useLocalSearchParams<\n TRoute extends Routes,\n TParams extends SearchParams = UnknownOutputParams,\n>(): RouteParams<TRoute, TParams>;\nexport function useLocalSearchParams<\n TParams1 extends SearchParams | Routes = UnknownOutputParams,\n TParams2 extends SearchParams = UnknownOutputParams,\n>(): RouteParams<TParams1, TParams2> {\n const params = React.useContext(LocalRouteParamsContext) ?? {};\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 RouteParams<TParams1, TParams2>;\n}\n\nexport function useSearchParams({ global = false } = {}): URLSearchParams {\n const globalRef = React.useRef(global);\n if (process.env.NODE_ENV !== 'production') {\n if (global !== globalRef.current) {\n console.warn(\n `Detected change in 'global' option of useSearchParams. This value cannot change between renders`\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const params = global ? useGlobalSearchParams() : useLocalSearchParams();\n const entries = Object.entries(params).flatMap(([key, value]) => {\n if (global) {\n if (key === 'params') return [];\n if (key === 'screen') return [];\n }\n\n return Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]];\n });\n\n return new ReadOnlyURLSearchParams(entries);\n}\n\nclass ReadOnlyURLSearchParams extends URLSearchParams {\n set() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n append() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n delete() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAEb,kDAA0B;AAE1B,mCAAkD;AAClD,8DAA0F;AAI1F;;;;;;;;;;;;;;GAcG;AACH,SAAgB,sBAAsB;IACpC,OAAO,IAAA,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E,CAAC;IACzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC9D,IAAI,MAAM,EAAE;YACV,IAAI,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;YAChC,IAAI,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;SACjC;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAtBD,0CAsBC;AAED,MAAM,uBAAwB,SAAQ,eAAe;IACnD,GAAG;QACD,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;CACF","sourcesContent":["'use client';\n\nimport React from 'react';\n\nimport { LocalRouteParamsContext } from './Route';\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { Router } from './imperative-api';\nimport { RouteParams, RouteSegments, UnknownOutputParams, Route } from './types';\n\n/**\n * Returns the [navigation state](https://reactnavigation.org/docs/navigation-state/)\n * of the navigator which contains the current screen.\n *\n * @example\n * ```tsx\n * import { useRootNavigationState } from 'expo-router';\n *\n * export default function Route() {\n * const { routes } = useRootNavigationState();\n *\n * return <Text>{routes[0].name}</Text>;\n * }\n * ```\n */\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/**\n * @deprecated Use [`useNavigationContainerRef`](#usenavigationcontainerref) instead,\n * which returns a React `ref`.\n */\nexport function useRootNavigation() {\n return store.navigationRef.current;\n}\n\n/**\n * @return The root `<NavigationContainer />` ref for the app. The `ref.current` may be `null`\n * if the `<NavigationContainer />` hasn't mounted yet.\n */\nexport function useNavigationContainerRef() {\n return store.navigationRef;\n}\n\n/**\n *\n * Returns the [Router](#router) object for imperative navigation.\n *\n * @example\n *```tsx\n * import { useRouter } from 'expo-router';\n * import { Text } from 'react-native';\n *\n * export default function Route() {\n * const router = useRouter();\n *\n * return (\n * <Text onPress={() => router.push('/home')}>Go Home</Text>\n * );\n *}\n * ```\n */\nexport function useRouter(): 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 reload: store.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\n * from a predefined universal link. For example, `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`.\n */\nexport function useUnstableGlobalHref(): string {\n return useStoreRouteInfo().unstable_globalHref;\n}\n\n/**\n * Returns a list of selected file segments for the currently selected route. Segments are not normalized,\n * so they will be the same as the file path. For example, `/[id]?id=normal` becomes `[\"[id]\"]`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n *\n *\n * `useSegments` can be typed using an abstract. Consider the following file structure:\n *\n * ```md\n * - app\n * - [user]\n * - index.tsx\n * - followers.tsx\n * - settings.tsx\n * ```\n *\n *\n * This can be strictly typed using the following abstract with `useSegments` hook:\n *\n * ```tsx\n * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()\n * ```\n */\nexport function useSegments<TSegments extends Route = Route>(): RouteSegments<TSegments>;\nexport function useSegments<TSegments extends RouteSegments<Route>>(): TSegments;\nexport function useSegments() {\n return useStoreRouteInfo().segments;\n}\n\n/**\n * Returns the currently selected route location without search parameters. For example, `/acme?foo=bar` returns `/acme`.\n * Segments will be normalized. For example, `/[id]?id=normal` becomes `/normal`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * Returns URL parameters for globally selected route, including dynamic path segments.\n * This function updates even when the route is not focused. Useful for analytics or\n * other background operations that don't draw to the screen.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * When querying search params in a stack, opt-towards using\n * [`useLocalSearchParams`](#uselocalsearchparams) because it will only update when the route is focused.\n *\n * > **Note:** For usage information, see\n * [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useGlobalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useGlobalSearchParams();\n *\n * return <Text>User: {user}</Text>;\n * }\n * ```\n */\nexport function useGlobalSearchParams<\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): TParams;\nexport function useGlobalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;\nexport function useGlobalSearchParams<\n TRoute extends Route,\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): RouteParams<TRoute> & TParams;\nexport function useGlobalSearchParams() {\n return useStoreRouteInfo().params;\n}\n\n/**\n * Returns the URL parameters for the contextually focused route. Useful for stacks where you may push a new screen\n * that changes the query parameters. For dynamic routes, both the route parameters and the search parameters are returned.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * To observe updates even when the invoking route is not focused, use [`useGlobalSearchParams`](#useglobalsearchparams).\n *\n * > **Note:** For usage information, see\n * [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useLocalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useLocalSearchParams();\n *\n * return <Text>User: {user}</Text>;\n * }\n */\nexport function useLocalSearchParams<\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): TParams;\nexport function useLocalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;\nexport function useLocalSearchParams<\n TRoute extends Route,\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): RouteParams<TRoute> & TParams;\nexport function useLocalSearchParams() {\n const params = React.useContext(LocalRouteParamsContext) ?? {};\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 any;\n}\n\nexport function useSearchParams({ global = false } = {}): URLSearchParams {\n const globalRef = React.useRef(global);\n if (process.env.NODE_ENV !== 'production') {\n if (global !== globalRef.current) {\n console.warn(\n `Detected change in 'global' option of useSearchParams. This value cannot change between renders`\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const params = global ? useGlobalSearchParams() : useLocalSearchParams();\n const entries = Object.entries(params).flatMap(([key, value]) => {\n if (global) {\n if (key === 'params') return [];\n if (key === 'screen') return [];\n }\n\n return Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]];\n });\n\n return new ReadOnlyURLSearchParams(entries);\n}\n\nclass ReadOnlyURLSearchParams extends URLSearchParams {\n set() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n append() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n delete() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n}\n"]}
|
|
@@ -1,26 +1,69 @@
|
|
|
1
1
|
import { NavigationOptions } from './global-state/routing';
|
|
2
|
-
import { Href,
|
|
2
|
+
import { Href, Route, RouteInputParams } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns `router` object for imperative navigation API.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*```tsx
|
|
8
|
+
* import { router } from 'expo-router';
|
|
9
|
+
* import { Text } from 'react-native';
|
|
10
|
+
*
|
|
11
|
+
* export default function Route() {
|
|
12
|
+
*
|
|
13
|
+
* return (
|
|
14
|
+
* <Text onPress={() => router.push('/home')}>Go Home</Text>
|
|
15
|
+
* );
|
|
16
|
+
*}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export type Router = {
|
|
4
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Goes back in the navigation history.
|
|
22
|
+
*/
|
|
5
23
|
back: () => void;
|
|
6
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Navigates to a route in the navigator's history if it supports invoking the `back` function.
|
|
26
|
+
*/
|
|
7
27
|
canGoBack: () => boolean;
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Navigates to the provided [`href`](#href) using a push operation if possible.
|
|
30
|
+
*/
|
|
31
|
+
push: (href: Href, options?: NavigationOptions) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Navigates to the provided [`href`](#href).
|
|
34
|
+
*/
|
|
35
|
+
navigate: (href: Href, options?: NavigationOptions) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Navigates to route without appending to the history. Can be used with
|
|
38
|
+
* [`useFocusEffect`](#usefocuseffecteffect-do_not_pass_a_second_prop)
|
|
39
|
+
* to redirect imperatively to a new screen.
|
|
40
|
+
*
|
|
41
|
+
* @see [Using `useRouter()` hook](/router/reference/redirects/) to redirect.
|
|
42
|
+
* */
|
|
43
|
+
replace: (href: Href, options?: NavigationOptions) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Navigates to the a stack lower than the current screen using the provided count if possible, otherwise 1.
|
|
46
|
+
*
|
|
47
|
+
* If the current screen is the only route, it will dismiss the entire stack.
|
|
48
|
+
*/
|
|
15
49
|
dismiss: (count?: number) => void;
|
|
16
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Returns to the first screen in the closest stack. This is similar to
|
|
52
|
+
* [popToTop](https://reactnavigation.org/docs/stack-actions/#poptotop) stack action.
|
|
53
|
+
*/
|
|
17
54
|
dismissAll: () => void;
|
|
18
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Checks if it is possible to dismiss the current screen. Returns `true` if the
|
|
57
|
+
* router is within the stack with more than one screen in stack's history.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
19
60
|
canDismiss: () => boolean;
|
|
20
|
-
/** Update the current route query params. */
|
|
21
|
-
setParams: <T extends Routes>(params: Partial<RouteParamInput<T>>) => void;
|
|
22
61
|
/**
|
|
23
|
-
*
|
|
62
|
+
* Updates the current route's query params.
|
|
63
|
+
*/
|
|
64
|
+
setParams: <T extends Route>(params: Partial<RouteInputParams<T>>) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Reloads the currently mounted route in experimental server mode. This can be used to re-fetch data.
|
|
24
67
|
* @hidden
|
|
25
68
|
*/
|
|
26
69
|
reload: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative-api.d.ts","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"imperative-api.d.ts","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;OAEG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB;;OAEG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACxD;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC5D;;;;;;SAMK;IACL,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC3D;;;;OAIG;IACH,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;;;OAIG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3E;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,MAWpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative-api.js","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;
|
|
1
|
+
{"version":3,"file":"imperative-api.js","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;AAyEpD;;GAEG;AACU,QAAA,MAAM,GAAW;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAC1D,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;IAClD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IACxC,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,UAAU,EAAE;IACpC,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,UAAU,EAAE;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;IACxD,IAAI,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,MAAM,EAAE;IAC1B,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,SAAS,EAAE;IAClC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAK,CAAC,SAAS,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,MAAM,EAAE;CAC7B,CAAC","sourcesContent":["import { store } from './global-state/router-store';\nimport { NavigationOptions } from './global-state/routing';\nimport { Href, Route, RouteInputParams } from './types';\n\n/**\n * Returns `router` object for imperative navigation API.\n *\n * @example\n *```tsx\n * import { router } from 'expo-router';\n * import { Text } from 'react-native';\n *\n * export default function Route() {\n *\n * return (\n * <Text onPress={() => router.push('/home')}>Go Home</Text>\n * );\n *}\n * ```\n */\nexport type Router = {\n /**\n * Goes back in the navigation history.\n */\n back: () => void;\n /**\n * Navigates to a route in the navigator's history if it supports invoking the `back` function.\n */\n canGoBack: () => boolean;\n /**\n * Navigates to the provided [`href`](#href) using a push operation if possible.\n */\n push: (href: Href, options?: NavigationOptions) => void;\n /**\n * Navigates to the provided [`href`](#href).\n */\n navigate: (href: Href, options?: NavigationOptions) => void;\n /**\n * Navigates to route without appending to the history. Can be used with\n * [`useFocusEffect`](#usefocuseffecteffect-do_not_pass_a_second_prop)\n * to redirect imperatively to a new screen.\n *\n * @see [Using `useRouter()` hook](/router/reference/redirects/) to redirect.\n * */\n replace: (href: Href, options?: NavigationOptions) => void;\n /**\n * Navigates to the a stack lower than the current screen using the provided count if possible, otherwise 1.\n *\n * If the current screen is the only route, it will dismiss the entire stack.\n */\n dismiss: (count?: number) => void;\n /**\n * Returns to the first screen in the closest stack. This is similar to\n * [popToTop](https://reactnavigation.org/docs/stack-actions/#poptotop) stack action.\n */\n dismissAll: () => void;\n /**\n * Checks if it is possible to dismiss the current screen. Returns `true` if the\n * router is within the stack with more than one screen in stack's history.\n *\n */\n canDismiss: () => boolean;\n /**\n * Updates the current route's query params.\n */\n setParams: <T extends Route>(params: Partial<RouteInputParams<T>>) => void;\n /**\n * Reloads the currently mounted route in experimental server mode. This can be used to re-fetch data.\n * @hidden\n */\n reload: () => void;\n};\n\n/**\n * @hidden\n */\nexport const router: Router = {\n navigate: (href, options) => store.navigate(href, options),\n push: (href, options) => store.push(href, options),\n dismiss: (count) => store.dismiss(count),\n dismissAll: () => store.dismissAll(),\n canDismiss: () => store.canDismiss(),\n replace: (href, options) => store.replace(href, options),\n back: () => store.goBack(),\n canGoBack: () => store.canGoBack(),\n setParams: (params) => store.setParams(params),\n reload: () => store.reload(),\n};\n"]}
|