reactjs – ESLint React-Router v4 – 如何验证Match params pr
发布时间:2020-12-15 20:48:09 所属栏目:百科 来源:网络整理
导读:我正在使用React-Router v4的 Match object将params传递给下一个组件.我的路由就像: Switch Route exact path="/" component={ExperimentListPage} / Route path="/experiment/:experiment" component={ExperimentResultsPage} //Switch 我的子组件看起来像
我正在使用React-Router v4的
Match object将params传递给下一个组件.我的路由就像:
<Switch> <Route exact path="/" component={ExperimentListPage} /> <Route path="/experiment/:experiment" component={ExperimentResultsPage} /> </Switch> 我的子组件看起来像: const ExperimentResultsPage = props => ( <ExperimentResultsContainer experimentName={props.match.params.experiment} /> ); export default withRouter(ExperimentResultsPage); 这一切都按预期工作,但是ESLint对我使用match.params.experiment非常不满意,并且在道具验证(react / prop-types)中缺少[eslint]’match.params.experiment’错误 我在React文档中看到我可以使用 有没有更好的方法将Match路径对象添加到道具验证?那会是什么样子?如果没有,我是否错过了其他可以帮助解决此问题的方法?
我碰到了类似的东西,eslint似乎很好,只是声明我使用道具并忽略匹配中未使用的字段:
match: PropTypes.shape({ params: PropTypes.shape({ experiment: PropTypes.string,}),}).isRequired, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |