在我的React容器/组件中,我可以使用哪种类型来引用React路由DOM包含的match
个部件?
interface Props {
match: any // <= What could I use here instead of any?
}
export class ProductContainer extends React.Component<Props> {
// ...
}
在我的React容器/组件中,我可以使用哪种类型来引用React路由DOM包含的match
个部件?
interface Props {
match: any // <= What could I use here instead of any?
}
export class ProductContainer extends React.Component<Props> {
// ...
}
您不需要明确地添加它.你可以用@types/react-router
中的RouteComponentProps<P>
作为props 的基本界面.P
是匹配参数的类型.
import { RouteComponentProps } from 'react-router';
// example route
<Route path="/products/:name" component={ProductContainer} />
interface MatchParams {
name: string;
}
interface Props extends RouteComponentProps<MatchParams> {
}
// from typings
import * as H from "history";
export interface RouteComponentProps<P> {
match: match<P>;
location: H.Location;
history: H.History;
staticContext?: any;
}
export interface match<P> {
params: P;
isExact: boolean;
path: string;
url: string;
}