React Typescript:添加位置状态以响应路由器组件 [英] React Typescript: add location state to react router component
问题描述
我有一条正常路线
function LoginPage(props: RouteComponentProps): React.ReactElement {...
}
使用 RouteComponentProps
c $ c> react-router-dom 。
that uses RouteComponentProps
from react-router-dom
.
很长一段时间以来,此组件没有任何问题,但现在它失败了当我使用 history.push(location.state.from.pathname)
说属性'from'在类型上不存在时,可以在travis-ci上编译'{}'。
Strangely there were no issues for a long time with this component, but now it is failing to compile on travis-ci when I use history.push(location.state.from.pathname)
saying Property 'from' does not exist on type '{}'.
我在PrivateRoute组件中设置了此状态,这对于重定向来说是非常标准的
I set this state in my PrivateRoute component that is pretty standard with a Redirect
<Redirect
to={{ pathname: '/login', state: { from: props.location } }}
/>
如何更新位置的输入 c包括一个
from
对象,该对象具有 pathname:string;
How can I update the typing for location
to include a from
object with pathname: string;
编辑:
解决方案是添加
COPY yarn.lock / usr / src / app /
复制完package.json后到我的Dockerfile中。
to my Dockerfile after I copied the package.json over.
推荐答案
好像您没有对软件包使用锁定文件。我建议您找到一个工作环境(在先前生成的docker映像中,或者从一个团队成员中),然后在其中生成package-lock.json(或yarn.lock)。我在 npm install --package-lock
中使用了此命令。它将首次为您提供帮助,直到问题完全解决为止。
Looks like you do not use lock files for the packages. I would suggest you find a working environment (in the previously generated docker image, or from one of the team members), and generate package-lock.json (or yarn.lock) there. I used this command for it npm install --package-lock
. It will help you for the first time until the issue will be solved completely.
这篇关于React Typescript:添加位置状态以响应路由器组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!