【发布时间】:2019-02-02 11:02:24
【问题描述】:
如果路径匹配,我正在尝试渲染容器组件。
class MyTopComponent extends Component {
componentDidUpdate() {
const params = getUrlParams(this.props.location);
if (params.id && params.id !== this.props.id) {
this.props.updateId(params.id);
}
}
render() {
const { a, b, c } = getUrlParams(this.props.location);
return this.props.id && this.props.isDataReady ? (
<div>
<Switch>
<Route path={MY_FIRST_PATH} component={MyContainer}/>
</Switch>
</div>
) : null;
}
}
问题是在转到路径后,然后返回,然后再次到路径,页面崩溃。 当我在组件中使用内联函数时它工作正常:
<Route path={MY_FIRST_PATH} component={() => <MyContainer/>}/>
第二种方式性能好吗?
【问题讨论】:
-
MY_FIRST_PATH定义在哪里? -
这是一个常数
标签: reactjs react-router react-router-dom