【发布时间】:2020-05-03 11:38:27
【问题描述】:
我们开始遇到这种错误。在代码像往常一样被编译之前,我们在编译过程中没有任何错误。 但是现在一些从头开始安装 react 应用程序的人只有在我们路由到新页面并尝试从位置状态中准备好属性时才开始收到此错误。
这是我们正在做的读取之前工作的状态:
interface IPageProps extends RouteComponentProps {...}
interface IState {
from: string;
to: string;
}
class Page extends Component<IPageProps, IState> {
constructor(props: IPageProps) {
super(props);
const {
location: { state: routeState },
history,
} = props;
this.state = {
from: routeState && routeState.from ? routeState.from : '',
to: routeState && routeState.to ? routeState.to : ''
};
}
}
所以错误在 routeState.from 和 routeState.to
react-routes 的版本:
"@types/react-router": "^5.1.1",
"@types/react-router-dom": "^4.3.5",
"react-router": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-5.1.2.tgz",
"integrity": "sha512-yjEuMFy1ONK246B+rsa0cUam5OeAQ8pyclRDgpxuSCrAlJ1qN9uZ5IgyKC7gQg0w8OM50NXHEegPh/ks9YuR2A==",
"requires": {
"@babel/runtime": "^7.1.2",
"history": "^4.9.0",
"hoist-non-react-statics": "^3.1.0",
"loose-envify": "^1.3.1",
"mini-create-react-context": "^0.3.0",
"path-to-regexp": "^1.7.0",
"prop-types": "^15.6.2",
"react-is": "^16.6.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0"
}
},
"react-router-dom": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.1.2.tgz",
"integrity": "sha512-7BPHAaIwWpZS074UKaw1FjVdZBSVWEk8IuDXdB+OkLb8vd/WRQIpA4ag9WQk61aEfQs47wHyjWUoUGGZxpQXew==",
"requires": {
"@babel/runtime": "^7.1.2",
"history": "^4.9.0",
"loose-envify": "^1.3.1",
"prop-types": "^15.6.2",
"react-router": "5.1.2",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0"
}
},
有人有同样的问题吗?你是怎么解决的?
令人担忧的是,这种情况以前没有发生,现在开始发生了。
提前致谢!
【问题讨论】:
标签: reactjs typescript react-router