umi的ts版本中的location

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的时候,该把他申明为什么类型么?

阅读 5.7k
1 个回答

你这用的是哪个版本的,现在最新的用的是 import { History, Location } from 'history-with-query';

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏