如教程所示https://reacttraining.com/react-router/web/example/modal-gallery (第 39 行)它说 let background = location.state && location.state.background;
。这样做我得到了错误:
Property 'background' does not exist on type '{}'. ts(2339)
注意:我正在使用 react-router-dom:“5.1.2”,react:“16.12.0”和 typescript:“~3.7.5”。
对此有什么想法吗?
最佳答案
//you need
import { Location } from 'history';
//than
const location = useLocation<{background: Location}>();
关于reactjs - 类型 'background' 上不存在属性 '{}' - React Router 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59931804/