在 TypeScript 中的类型定义
React Router DOM 中的组件都继承自 React.Component,并且分别根据其所接受的 props 定义了专用的类型。由于 props 类型已经内置,在一般使用时,可以不必显式声明 props 类型。常用的类型、函数及其声明主要有以下这些。
History<LocationState>BrowserRouterHashRouterLink<History.LocationState>NavLink<History.LocationState>RoutePropsRoute<T extends RouteProps>SwitchuseHistory(): History<HistoryLocationState>useLocation(): History.Location<History.LocationState>useParams(): { [p in keyof Params]: string }useRouteMatch(path?: string | string[] | RouteProps): match<Params> | null