-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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: Strengthen route typings #9366
Changes from all commits
56022e7
4c331d0
093a5c0
d3cdf1a
c7e50a1
e0903d5
8b6d8ed
e4cc495
5f2a196
7622a69
7b7090e
7cbacec
070abd4
ac23968
6d72e41
7bee9dc
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"react-router": patch | ||
"react-router-dom": patch | ||
"react-router-native": patch | ||
"@remix-run/router": patch | ||
--- | ||
|
||
fix: Strengthen RouteObject/RouteProps types and throw on index routes with children (#9366) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
- goldins | ||
- gowthamvbhat | ||
- GraxMonzo | ||
- GuptaSiddhant | ||
- haivuw | ||
- hernanif1 | ||
- hongji00 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,55 @@ | ||
import * as React from "react"; | ||
import type { | ||
TrackedPromise, | ||
AgnosticRouteMatch, | ||
AgnosticIndexRouteObject, | ||
AgnosticNonIndexRouteObject, | ||
History, | ||
Location, | ||
Router, | ||
StaticHandlerContext, | ||
To, | ||
AgnosticRouteObject, | ||
AgnosticRouteMatch, | ||
TrackedPromise, | ||
} from "@remix-run/router"; | ||
import type { Action as NavigationType } from "@remix-run/router"; | ||
|
||
// Create react-specific types from the agnostic types in @remix-run/router to | ||
// export from react-router | ||
export interface RouteObject extends AgnosticRouteObject { | ||
export interface IndexRouteObject { | ||
caseSensitive?: AgnosticIndexRouteObject["caseSensitive"]; | ||
path?: AgnosticIndexRouteObject["path"]; | ||
id?: AgnosticIndexRouteObject["id"]; | ||
loader?: AgnosticIndexRouteObject["loader"]; | ||
action?: AgnosticIndexRouteObject["action"]; | ||
hasErrorBoundary: AgnosticIndexRouteObject["hasErrorBoundary"]; | ||
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. @brophdawg11 I'm a bit late to the party, but better late than never: while testing the prerelease for #9352 I noticed this property had suddenly become required. I'm assuming this might be unintentional? 😊 Same goes for 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. Oh thank you! Yes that's definitely a typo :) |
||
shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"]; | ||
handle?: AgnosticIndexRouteObject["handle"]; | ||
index: true; | ||
children?: undefined; | ||
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. why |
||
element?: React.ReactNode | null; | ||
errorElement?: React.ReactNode | null; | ||
} | ||
|
||
export interface NonIndexRouteObject { | ||
caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"]; | ||
path?: AgnosticNonIndexRouteObject["path"]; | ||
id?: AgnosticNonIndexRouteObject["id"]; | ||
loader?: AgnosticNonIndexRouteObject["loader"]; | ||
action?: AgnosticNonIndexRouteObject["action"]; | ||
hasErrorBoundary: AgnosticNonIndexRouteObject["hasErrorBoundary"]; | ||
shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"]; | ||
handle?: AgnosticNonIndexRouteObject["handle"]; | ||
index?: false; | ||
children?: RouteObject[]; | ||
element?: React.ReactNode | null; | ||
errorElement?: React.ReactNode | null; | ||
} | ||
|
||
export interface DataRouteObject extends RouteObject { | ||
export type RouteObject = IndexRouteObject | NonIndexRouteObject; | ||
|
||
export type DataRouteObject = RouteObject & { | ||
children?: DataRouteObject[]; | ||
id: string; | ||
} | ||
}; | ||
|
||
export interface RouteMatch< | ||
ParamKey extends string = string, | ||
|
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.
Got rid of the duplication here -
<Route>
props are now justRouteObject
equivalents that expectReactNode
children instead ofReactElement
children