-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix docs #7168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix docs #7168
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: | |
|
|
||
| - **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 | ||
| - The **router** will automatically throw a not-found error when a path does not match any known route matching pattern | ||
| - 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. | ||
| - 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. | ||
| - Examples: | ||
| - Attempting to access `/users` when there is no `/users` route | ||
| - Attempting to access `/posts/1/edit` when the route tree only handles `/posts/$postId` | ||
| - **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 | ||
| - **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. | ||
| - Will be handled by the nearest parent route with a `notFoundComponent` (when `notFound` is called within `loader`) or the root route. | ||
| - Will be handled by the nearest matching route with a `notFoundComponent` (when `notFound` is called within `loader`) or the root route. | ||
| - Examples: | ||
| - Attempting to access `/posts/1` when the post with ID 1 does not exist | ||
| - 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 | |
|
|
||
| ### `notFoundMode: 'fuzzy'` | ||
|
|
||
| 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. | ||
| 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`. | ||
|
|
||
| > **❓ 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. | ||
|
|
||
| The nearest suitable route is found using the following criteria: | ||
|
|
||
| - The route must have children and therefore an `Outlet` to render the `notFoundComponent` | ||
| - The route must have a `notFoundComponent` configured or the router must have a `defaultNotFoundComponent` configured | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing critical criterion: route must have children. Based on the implementation (see comment on line 13), the criteria should include:
🤖 Prompt for AI Agents |
||
|
|
||
| For example, consider the following route tree: | ||
|
|
@@ -53,9 +52,10 @@ If provided the path of `/posts/1/edit`, the following component structure will | |
|
|
||
| - `<Root>` | ||
| - `<Posts>` | ||
| - `<Posts.notFoundComponent>` | ||
| - `<Post>` | ||
| - `<Post.notFoundComponent>` | ||
|
|
||
| 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**. | ||
| The `notFoundComponent` of the `$postId` route will be rendered because it is the **nearest matching route with a `notFoundComponent` configured**. | ||
|
Comment on lines
+55
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example contradicts the actual implementation behavior. Given the route tree structure where The correct rendering for The 🤖 Prompt for AI Agents |
||
|
|
||
| ### `notFoundMode: 'root'` | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/router
Length of output: 3830
🏁 Script executed:
Repository: TanStack/router
Length of output: 15266
Document the actual selection criteria for fuzzy mode: routes must have
children, notnotFoundComponent.The documentation on lines 13, 19, 37, 43, and 55-58 incorrectly describes how fuzzy mode selects which route handles a not-found error. The implementation (packages/router-core/src/router.ts:3163-3176) selects based on whether a route has children, not whether it has a configured
notFoundComponent:The
notFoundComponent(ordefaultNotFoundComponent) is required to render something, but is not the criterion for route selection. The selection criteria should be: the nearest route withchildren(layout routes), not the presence of anotFoundComponent.🤖 Prompt for AI Agents