import { Route, Redirect } from 'react-router'
<Route exact path="/" render={() => (
loggedIn ? (
<Redirect to="/dashboard"/>
) : (
<PublicHomePage/>
)
)}/>
<Route exact path="/">
{loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>
window.location.href = 'http://domain.com';
<Redirect to="/somewhere/else" />
state = { redirect: null };
render() {
if (this.state.redirect) {
return <Redirect to={this.state.redirect} />
}
return(
// Your Code goes here
)
}
// update the redirect
this.setState({ redirect: "/someRoute" });
state = { redirect: null };
render() {
if (this.state.redirect) {
return <Redirect to={this.state.redirect} />
}
return(
// Your Code goes here
)
}
<span className="input-group-btn">
<Link to="/login" />Click to login</Link>
</span>