reactjs - componentDidMount 有趣的问题
问题描述
我有以下代码
componentDidMount() {
if (this.props && this.props.match && this.props.match.params.code) {
console.dir("mount1");
this._handleCode(this.props.match.params.code);
} else {
console.dir("mount2");
this.setState({loading: false});
}
}
当 url 参数中有代码时,为什么先打印 mount2 然后再打印 mount1?前任。/subscriptionGroup/测试
<ProtectedRoute path="/subscriptioncode/:code" component={SubscriptionCodeActivate}/>
const ProtectedRoute = ({
path,
component: Component,
render,
...rest
}) => {
return (
<Route
path={path}
{...rest}
render={props => {
if (Utils.isAuthenticated()) {
return Component ? <Component {...props} /> : render(props);
} else {
return <Redirect to={`/login?redirect=${props.location.pathname}`} />;
}
}}
/>
);
};
解决方案
推荐阅读
- android - Kotlin CoroutineScope 初始化依赖于 CoroutineContext 和自定义 getter
- javascript - 我可以将一整套列组合在一个表格中并使用粘性吗?
- css - Bootstrap 的 div 之间的边距
- python - Scrapy爬虫递归解析数据无法回调
- android - smoothScollToPosition 不是从右到左
- neo4j - 如何展开集合、执行操作并为流中的每条记录重新组合集合?
- java - 如何从连续点列表中创建部分列表
- facebook - Ruby gem facebook_ads exception_with_response:400 错误请求
- typescript - 从外部访问私人财产
- c# - 绑定 TextBlock C# 中的标签