Merge pull request #15314 from donaldpipowitch/patch-4

fixed match interface in react-router v4
This commit is contained in:
Paul van Brenk
2017-03-23 16:39:52 -07:00
committed by GitHub
3 changed files with 17 additions and 16 deletions

View File

@@ -10,7 +10,6 @@ declare module 'react-router-dom' {
MemoryRouter,
Redirect,
RouteComponentProps,
PartialRouteComponentProps,
RouteProps,
Route,
Router,
@@ -68,7 +67,6 @@ declare module 'react-router-dom' {
MemoryRouter,
Redirect,
RouteComponentProps, // TypeScript specific, not from React Router itself
PartialRouteComponentProps, // TypeScript specific, not from React Router itself
RouteProps, // TypeScript specific, not from React Router itself
Route,
Router,

View File

@@ -48,12 +48,9 @@ declare module 'react-router' {
history: H.History;
}
interface PartialRouteComponentProps<P> extends Partial<RouteComponentProps<P>> {
}
interface RouteProps {
location?: H.Location;
component?: React.SFC<PartialRouteComponentProps<any> | void> | React.ComponentClass<PartialRouteComponentProps<any> | void>;
component?: React.SFC<RouteComponentProps<any> | void> | React.ComponentClass<RouteComponentProps<any> | void>;
render?: (props: RouteComponentProps<any>) => React.ReactNode;
children?: (props: RouteComponentProps<any>) => React.ReactNode | React.ReactNode;
path?: string;
@@ -84,13 +81,13 @@ declare module 'react-router' {
interface match<P> {
params: P;
isExact?: boolean;
path?: string;
url?: string;
isExact: boolean;
path: string;
url: string;
}
function matchPath<P>(pathname: string, props: RouteProps): match<P>;
function matchPath<P>(pathname: string, props: RouteProps): match<P> | null;
function withRouter(component: React.SFC<RouteComponentProps<any>> | React.ComponentClass<RouteComponentProps<any>>): React.ComponentClass<any>;
@@ -101,7 +98,6 @@ declare module 'react-router' {
Prompt,
Redirect,
RouteComponentProps, // TypeScript specific, not from React Router itself
PartialRouteComponentProps, // TypeScript specific, not from React Router itself
RouteProps, // TypeScript specific, not from React Router itself
Route,
Router,

View File

@@ -23,11 +23,18 @@ const RecursiveExample = () => (
</Router>
)
interface PersonProps extends Partial<RouteComponentProps<{id: number}>> {
match: match<{id: number}>;
interface InitialPersonProps {
match: {
params: {
id: number;
};
url: string;
};
}
const Person: React.SFC<PersonProps> = ({ match }) => {
type PersonProps = RouteComponentProps<{ id: number }>;
const Person: React.SFC<InitialPersonProps | PersonProps> = ({ match }) => {
const person = find(match.params.id)
return (
@@ -42,9 +49,9 @@ const Person: React.SFC<PersonProps> = ({ match }) => {
</li>
))}
</ul>
<Route path={`${match.url}/:id`} component={Person}/>
<Route path={`${match.url}/:id`} component={Person as React.SFC<PersonProps>}/>
</div>
)
}
export default RecursiveExample
export default RecursiveExample