If I'm always redirecting to in-app routes, what's the difference between the Redirect
component in react-router-dom (v4), and this.props.history.push()
?
E.g. let's say I want to add a user-given title to the URL and redirect from /foo/123
to /foo/123/some-title
(both rendered with same Route/component).
I see in some uses of Redirect
passing in state. Where does this end up?
Is it an anti-pattern to specify where you want to redirect to in the state? Why doesn't example code look like this:
save() {
this.setState({ redir: '/new-path'; });
}
...
render () {
if (this.state.redir) {
return <Redirect to={this.state.redir} />;
}
...
}
See Question&Answers more detail:os