React-Router history push code example
Example 1: react router history push parameter
this.props.history.push({
pathname: '/template',
search: '?query=abc',
state: { detail: response.data }
})
Example 2: history.push
<Link to="/somewhere"/>
const location = {
pathname: '/somewhere',
state: { fromDashboard: true }
}
<Link to={location}/>
<Redirect to={location}/>
history.push(location)
history.replace(location)
Example 3: history.push
class Comp extends React.Component {
componentDidUpdate(prevProps) {
const locationChanged =
this.props.location !== prevProps.location;
const locationChanged =
this.props.history.location !== prevProps.history.location;
}
}
<Route component={Comp} />;