History.push 仅在参数更改时不会重定向,但会更改浏览器中的 url

问题描述

我有这条路线:

   <PrivateRoute path="/profile/:user_id" exact component={GenericProfile} />;

这是 PrivateRoute 组件:

const PrivateRoute = ({ component: Component,auth,...rest }) => {
  return (
    <Route
      {...rest}
      render={(props) =>
        auth.isAuthenticated === true ? (
          <Component {...props} />
        ) : (
          <Redirect to="/login" />
        )
      }
    />
  );
};

PrivateRoute.propTypes = {
  auth: PropTypes.object.isrequired,};

const mapStatetoProps = (state) => ({
  auth: state.auth,});

export default connect(mapStatetoProps)(PrivateRoute);

这是它在 App.js 中的使用方式:

当我在个人资料页面并且我有一个重定向到另一个个人资料的按钮时:

    <Button onClick={()=>{
       this.props.history.push("/profile/" + another_user_id)
                   }}>
      Redirect to another profile
    </Button>

浏览器中的 url 发生了变化,但没有任何反应。
我实际上并没有重定向到另一个配置文件

注意: 对于许多开发人员来说,这似乎是一个反复出现的问题。没有提出的解决方案对我有用。所以我写这个是因为我怀疑我的情况有点不同。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)