Hello my problem is that after i redirect to a component using history.push() i pass some user details there and pass it through the problem is when you hit refresh or redirect into another component everything is lost even its undefined. i have found solutions here but only if your on the same server i think. Since i am using java jersey api i cannot use the solutions provided there https://stackoverflow.com/a/36623117/11416547, btw setting the variables into state dosen't work either. Thanks for any help in advance.
onSubmit = e => {
        e.preventDefault();
        fetch(  `/myresource/customer/auth/${this.state.query}/${this.state.password}`,
            {
                method: "POST",
                headers: {
                    credentials: "same-origin"
                },
                credentials: "include",
            })
            .then(res => res.json())
            .then((result) => {
                    this.setState({
                       user: result.customer,
                    });
                    console.log(result.customer);
                    this.cookies.set('token', result.newCookie, { path: '/' });
                    console.log(this.cookies.get('token'));
                    const { history } = this.props;
                    if(history) history.push({
                        pathname: '/dashboard/',                   <-- here i redirect to this component and pass user there
                        search: '',
                        state: {user: result.customer}
                    });
                }
            )
    }
this is my dashboard Component
 constructor(props) {
    super(props);
    this.state = {
        userName: '',
    }
}
componentDidMount() {
    if (typeof(this.props.location.state) != "undefined" ) {  
        this.setState( {userName: this.props.location.state.user.userName},
            () => {userName: this.props.location.state.user.userName}
        );
    }
}
render() {
    return (
      <Container>
          <div>{this.state.userName}</div>
      </Container>
    );
}
I am asking how to keep the state alive on the client side after i redirect to a component with history.push i am not trying to achieve the ``` history.push```  functionality for which is asked in the possible duplicated question how to redirect.