I used HashRouter for setting up routes in react. I try to redirect to some other component after api call, but it shows a warning("Warning: Hash history cannot push state; it is ignored).
Routing Code
<HashRouter>
<div ref={el => (this.div = el)}>
<Switch>
<Route path="/" component={Home} exact />
<Route path="/register" component={Register} exact />
<Route path="/login" component={Register} exact />
<Route path="/verification" component={Verification} exact />
<Route path="/user-dashboard" component={Profile} exact />
<Route path="/logout" component={Profile} exact />
<Route path="/contact-us" component={Contact} exact />
<Route path="/terms-and-conditions" render={({ match }) => <TermCondition />} exact />
<Route path="/forgot-password" render={({ match }) => <ForgotPassword />} exact />
<Route path="/reset/:token" render={({ match }) => <Reset token={match.params.token} />}exact />
<Route path="/new-label" component={NewLabel} exact />
<Route component={NoMatchPage} />
</Switch>
</div>
</HashRouter>
Axios calling where is used history.push
Axios.post(ApiProvider.endpoint + `/login`, loginData, {
headers: headers
})
.then(result => {
this.props.history.push('/verification', { email: this.state.email });
toast.success(result.data.message);
})
.catch(error => {
toast.error(error.response.data.message);
})