redirect react js

JavaScript
window.location.href = "http://mywebsite.com/home.html";import { Route, Redirect } from 'react-router'

<Route exact path="/" render={() => (
  loggedIn ? (
    <Redirect to="/dashboard"/>
  ) : (
    <PublicHomePage/>
  )
)}/><Route exact path="/">
  {loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>
state = { redirect: null };
render() {
  if (this.state.redirect) {
    return <Redirect to={this.state.redirect} />
  }
  return(
  // Your Code goes here
  )
}
<Redirect to="/somewhere/else" />
import { useHistory } from "react-router-dom";

function App() {
  let history = useHistory();
}

Source

Also in JavaScript: