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
{{ message }}
Repository navigation
Commit 16de974
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/router/guide/not-found-errors.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,13 @@ There are 2 uses for not-found errors in TanStack Router:
10
10
11
11
-**Non-matching route paths**: When a path does not match any known route matching pattern **OR** when it partially matches a route, but with extra path segments
12
12
- The **router** will automatically throw a not-found error when a path does not match any known route matching pattern
13
-
- If the router's `notFoundMode` is set to `fuzzy`, the nearest parent route with a `notFoundComponent` will handle the error. If the router's `notFoundMode` is set to `root`, the root route will handle the error.
13
+
- If the router's `notFoundMode` is set to `fuzzy`, the nearest matching route with a `notFoundComponent` will handle the error. If the router's `notFoundMode` is set to `root`, the root route will handle the error.
14
14
- Examples:
15
15
- Attempting to access `/users` when there is no `/users` route
16
16
- Attempting to access `/posts/1/edit` when the route tree only handles `/posts/$postId`
17
17
-**Missing resources**: When a resource cannot be found, such as a post with a given ID or any asynchronous data that is not available or does not exist
18
18
-**You, the developer** must throw a not-found error when a resource cannot be found. This can be done in the `beforeLoad` or `loader` functions using the `notFound` utility.
19
-
- Will be handled by the nearest parent route with a `notFoundComponent` (when `notFound` is called within `loader`) or the root route.
19
+
- Will be handled by the nearest matching route with a `notFoundComponent` (when `notFound` is called within `loader`) or the root route.
20
20
- Examples:
21
21
- Attempting to access `/posts/1` when the post with ID 1 does not exist
22
22
- Attempting to access `/docs/path/to/document` when the document does not exist
@@ -34,13 +34,12 @@ Depending on the `notFoundMode` option, the router will handle these automatic e
34
34
35
35
### `notFoundMode: 'fuzzy'`
36
36
37
-
By default, the router's `notFoundMode` is set to `fuzzy`, which indicates that if a pathname doesn't match any known route, the router will attempt to use the closest matching route with children/(an outlet) and a configured not found component.
37
+
By default, the router's `notFoundMode` is set to `fuzzy`, which indicates that if a pathname doesn't match any known route, the router will attempt to use the closest matching route with a configured `notFoundComponent`.
38
38
39
39
> **❓ Why is this the default?** Fuzzy matching to preserve as much parent layout as possible for the user gives them more context to navigate to a useful location based on where they thought they would arrive.
40
40
41
41
The nearest suitable route is found using the following criteria:
42
42
43
-
- The route must have children and therefore an `Outlet` to render the `notFoundComponent`
44
43
- The route must have a `notFoundComponent` configured or the router must have a `defaultNotFoundComponent` configured
45
44
46
45
For example, consider the following route tree:
@@ -53,9 +52,10 @@ If provided the path of `/posts/1/edit`, the following component structure will
53
52
54
53
-`<Root>`
55
54
-`<Posts>`
56
-
-`<Posts.notFoundComponent>`
55
+
-`<Post>`
56
+
-`<Post.notFoundComponent>`
57
57
58
-
The `notFoundComponent` of the `posts` route will be rendered because it is the **nearest suitable parent route with children (and therefore an outlet) and a `notFoundComponent` configured**.
58
+
The `notFoundComponent` of the `$postId` route will be rendered because it is the **nearest matching route with a `notFoundComponent` configured**.
0 commit comments