You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{/* `default` prop indicates a fallback route. Useful for 404 pages */}
35
35
<NotFound default />
36
36
</Router>
@@ -41,9 +41,7 @@ const App = () => (
41
41
42
42
**Progressive Hydration:** When the app is hydrated on the client, the route (`Home` or `Profile` in this case) suspends. This causes hydration for that part of the page to be deferred until the route's `import()` is resolved, at which point that part of the page automatically finishes hydrating.
43
43
44
-
**Seamless Routing:** Switch switching between routes on the client, the Router is aware of asynchronous dependencies in routes. Instead of clearing the current route and showing a loading spinner while waiting for the next route (or its data), the router preserves the current route in-place until the incoming route has finished loading, then they are swapped.
45
-
46
-
**Nested Routing:** Nested routes are supported by using multiple `Router` components. Partially matched routes end with a wildcard `/*` and the remaining value will be passed to continue matching with if there are any further routes.
44
+
**Seamless Routing:** When switching between routes on the client, the Router is aware of asynchronous dependencies in routes. Instead of clearing the current route and showing a loading spinner while waiting for the next route, the router preserves the current route in-place until the incoming route has finished loading, then they are swapped.
47
45
48
46
## Prerendering
49
47
@@ -74,6 +72,46 @@ export async function prerender(data) {
74
72
}
75
73
```
76
74
75
+
## Nested Routing
76
+
77
+
Nested routes are supported by using multiple `Router` components. Partially matched routes end with a wildcard (`/*`) and the remaining value will be passed to continue matching with if there are any further routes.
@@ -84,7 +122,7 @@ A context provider that provides the current location to its children. This is r
84
122
85
123
Props:
86
124
87
-
-`scope?: string | RegExp` - Sets a scope for the paths that the router will handle (intercept). If a path does not match the scope, either by starting with the provided string or matching the RegExp, the router will ignore it and default browser navigation will apply.
125
+
-`scope?: string | RegExp` - Sets a scope for the paths that the router will handle (intercept). If a path does not match the scope, either by starting with the provided string or matching the RegExp, the router will ignore it and default browser navigation will apply.
88
126
89
127
Typically, you would wrap your entire app in this provider:
90
128
@@ -102,9 +140,9 @@ const App = () => (
102
140
103
141
Props:
104
142
105
-
-`onRouteChange?: (url: string) => void` - Callback to be called when a route changes.
106
-
-`onLoadStart?: (url: string) => void` - Callback to be called when a route starts loading (i.e., if it suspends). This will not be called before navigations to sync routes or subsequent navigations to async routes.
107
-
-`onLoadEnd?: (url: string) => void` - Callback to be called after a route finishes loading (i.e., if it suspends). This will not be called after navigations to sync routes or subsequent navigations to async routes.
143
+
-`onRouteChange?: (url: string) => void` - Callback to be called when a route changes.
144
+
-`onLoadStart?: (url: string) => void` - Callback to be called when a route starts loading (i.e., if it suspends). This will not be called before navigations to sync routes or subsequent navigations to async routes.
145
+
-`onLoadEnd?: (url: string) => void` - Callback to be called after a route finishes loading (i.e., if it suspends). This will not be called after navigations to sync routes or subsequent navigations to async routes.
-`default?: boolean` - If set, this route is a fallback/default route to be used when nothing else matches
199
+
-`path: string` - The path to match (read on)
200
+
-`default?: boolean` - If set, this route is a fallback/default route to be used when nothing else matches
161
201
162
202
Specific to the `Route` component:
163
203
164
-
-`component: AnyComponent` - The component to render when the route matches
204
+
-`component: AnyComponent` - The component to render when the route matches
165
205
166
206
#### Path Segment Matching
167
207
168
208
Paths are matched using a simple string matching algorithm. The following features may be used:
169
209
170
-
-`:param` - Matches any URL segment, binding the value to the label (can later extract this value from `useRoute()`)
171
-
-`/profile/:id` will match `/profile/123` and `/profile/abc`
172
-
-`/profile/:id?` will match `/profile` and `/profile/123`
173
-
-`/profile/:id*` will match `/profile`, `/profile/123`, and `/profile/123/abc`
174
-
-`/profile/:id+` will match `/profile/123`, `/profile/123/abc`
175
-
-`*` - Matches one or more URL segments
176
-
-`/profile/*` will match `/profile/123`, `/profile/123/abc`, etc.
210
+
-`:param` - Matches any URL segment, binding the value to the label (can later extract this value from `useRoute()`)
211
+
-`/profile/:id` will match `/profile/123` and `/profile/abc`
212
+
-`/profile/:id?` will match `/profile` and `/profile/123`
213
+
-`/profile/:id*` will match `/profile`, `/profile/123`, and `/profile/123/abc`
214
+
-`/profile/:id+` will match `/profile/123`, `/profile/123/abc`
215
+
-`*` - Matches one or more URL segments
216
+
-`/profile/*` will match `/profile/123`, `/profile/123/abc`, etc.
177
217
178
218
These can then be composed to create more complex routes:
179
219
180
-
-`/profile/:id/*` will match `/profile/123/abc`, `/profile/123/abc/def`, etc.
220
+
-`/profile/:id/*` will match `/profile/123/abc`, `/profile/123/abc/def`, etc.
181
221
182
222
The difference between `/:id*` and `/:id/*` is that in the former, the `id` param will include the entire path after it, while in the latter, the `id` is just the single path segment.
183
223
184
-
-`/profile/:id*`, with `/profile/123/abc`
185
-
-`id` is `123/abc`
186
-
-`/profile/:id/*`, with `/profile/123/abc`
224
+
-`/profile/:id*`, with `/profile/123/abc`
225
+
-`id` is `123/abc`
226
+
-`/profile/:id/*`, with `/profile/123/abc`
187
227
-`id` is `123`
188
228
189
229
### `useLocation`
@@ -192,21 +232,20 @@ A hook to work with the `LocationProvider` to access location context.
192
232
193
233
Returns an object with the following properties:
194
234
195
-
-`url: string` - The current path & search params
196
-
-`path: string` - The current path
197
-
-`query: Record<string, string>` - The current query string parameters (`/profile?name=John` -> `{ name: 'John' }`)
198
-
-`route: (url: string, replace?: boolean) => void` - A function to programmatically navigate to a new route. The `replace` param can optionally be used to overwrite history, navigating them away without keeping the current location in the history stack.
235
+
-`url: string` - The current path & search params
236
+
-`path: string` - The current path
237
+
-`query: Record<string, string>` - The current query string parameters (`/profile?name=John` -> `{ name: 'John' }`)
238
+
-`route: (url: string, replace?: boolean) => void` - A function to programmatically navigate to a new route. The `replace` param can optionally be used to overwrite history, navigating them away without keeping the current location in the history stack.
199
239
200
240
### `useRoute`
201
241
202
242
A hook to access current route information. Unlike `useLocation`, this hook only works within `<Router>` components.
203
243
204
244
Returns an object with the following properties:
205
245
206
-
207
-
-`path: string` - The current path
208
-
-`query: Record<string, string>` - The current query string parameters (`/profile?name=John` -> `{ name: 'John' }`)
209
-
-`params: Record<string, string>` - The current route parameters (`/profile/:id` -> `{ id: '123' }`)
246
+
-`path: string` - The current path
247
+
-`query: Record<string, string>` - The current query string parameters (`/profile?name=John` -> `{ name: 'John' }`)
248
+
-`params: Record<string, string>` - The current route parameters (`/profile/:id` -> `{ id: '123' }`)
0 commit comments