解决方案

在路由组件上最上层元素上加一个key增加路由的识别度 this.props.location.key

  1. // 组件挂载
  2. componentDidMount() {
  3. console.log(this.props.location);
  4. }

image.png

  1. <div className={style.content} key={this.props.location.key}>
  2. <CSSTransition
  3. key={this.props.location.pathname}>
  4. <Switch location={this.props.location}>
  5. {routes.map(r => (
  6. <Route key={r.key} supKey={r.supKey} path={r.path} exact={r.exact} component={r.component} />
  7. ))}
  8. </Switch>
  9. </CSSTransition>
  10. </div>