react router redirect
<Route exact path="/">
{loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>
react router redirect
<Route exact path="/">
{loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>
History push for redirecting to another page in react-router v6
import React from 'react';
const LocationContext = React.createContext();
export default function Router({ children }) {
return (
<LocationContext.Provider
value={{
// The current location
location: window.location,
navigator: {
// Change url and push entry in the history
push(to) {
window.history.pushState(null, null, to);
},
// Change url and replace the last entry in the history
replace(to) {
window.history.replaceState(null, null, to);
},
// Go back to the previous entry in the history
back() {
window.history.go(-1);
},
// Go forward to the next entry in the history
forward() {
window.history.go(1);
},
// If we want to go forward or
// backward from more than 1 step
go(step) {
window.history.go(step);
}
}
}}
>
{children}
</LocationContext.Provider>
);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us