import { Dispatch, History, Location } from 'umi'
const TableList: React.FC<{ location: Location, history: History, dispatch: Dispatch }> = (props) => {
const { location, history, dispatch } = props
// 提示Location没有query属性
const { query } = location
}
看源码是umi中是使用的history-with-umi
,这个库的申明中
export interface Location<S = LocationState> {
pathname: Pathname;
search: Search;
state: S;
hash: Hash;
key?: LocationKey;
}
export interface LocationDescriptorObject<S = LocationState> {
pathname?: Pathname;
search?: Search;
state?: S;
hash?: Hash;
key?: LocationKey;
query?: {[key: string]: any};
}
但是umi中导出的时候,只用了Location
import { History, Location } from 'history-with-query';`
导致我下面两种形式都无法使用
import { LocationDescriptorObject } form 'history-with-query'
import { `LocationDescriptorObject` } from 'umi'
那么umi中,我们用Location的时候,该把他申明为什么类型么?
你这用的是哪个版本的,现在最新的用的是
import { History, Location } from 'history-with-query';