How to pass params with history.push/Link/Redirect in react-router v4?

前端 未结 10 941
你的背包
你的背包 2020-11-22 04:27

How can we pass parameter with this.props.history.push(\'/page\') in React-Router v4?

.then(response => {
       var r = this;
        if (re         


        
10条回答
  •  太阳男子
    2020-11-22 05:13

    React TypeScript with Hooks

    From a Class

      this.history.push({
          pathname: "/unauthorized",
          state: { message: "Hello" },
        });
    

    UnAuthorized Functional Component

    interface IState {
      message?: string;
    }
    
    export default function UnAuthorized() {
      const location = useLocation();
      const message = (location.state as IState).message;
    
      return (
        
    {message}
    ); }

提交回复
热议问题