在我的React容器/组件中,我可以使用哪种类型来引用matchReact Router DOM包含的部分?
match
interface Props { match: any // <= What could I use here instead of any? } export class ProductContainer extends React.Component<Props> { // ... }
您无需显式添加。您可以改用RouteComponentProps<P>from @types/react- router作为道具的基本接口。P是您的比赛参数的类型。
RouteComponentProps<P>
@types/react- router
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 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; }