Replies: 1 comment
-
|
An implementation of Solution 2 is available: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Current problem
Currently the
notFound()function accepts a params object with the shape ofNotFoundErrorthat is then passed as props to thenotFoundComponent.Arbitrary data can be sent through this mechanism with the
data?: anykey ofNotFoundError, but this any prevents us from creating type-safe "not found" errors.router/packages/react-router/src/not-found.tsx
Lines 8 to 23 in 2088be2
Goals
Some applications might need to present a different version of the
notFoundComponentdepending on how/where/why thenotFounderror was thrown. We can imagine a few cases:Each of the above examples might require some custom props to function properly, in addition to requiring a way to determine which of these to display (assuming an app that uses all 3).
For this reason, this RFC proposes that we should allow users to type the
datakey.Possible solutions
We consider that it is not the role of the
notFoundComponentto handle this variety of cases, and each route should be responsible for displaying such screens. Users can define their own component and pass props to it, there is no need to complexify the route API.// no code sample, this solution changes nothingWe allow users to type the
datakey globally, through interface augmentation. Most apps probably don't need a huge variety of "not found" screens, and so simple patterns, globally declared, are probably enough. For example:tanstack/router should be the most type-safe router out there, so we need to strongly type the
datakey on a per-route basis. This can be done through inferring thedatatype from theerrorComponentprops, and enforce those types using therouteIdkey of theNotFoundErrorConsiderations
datakey is typed asany, and so changing the type to anything else might cause type errors in some applications. However, all 3 of the solutions proposed above can be implemented with no (or minimal) implications for this.Beta Was this translation helpful? Give feedback.
All reactions