Redirection React Router
<Route exact path="/">
{loggedIn ? <Redirect to="/profile" /> : <HomePage />}
</Route>
Kaotik
<Route exact path="/">
{loggedIn ? <Redirect to="/profile" /> : <HomePage />}
</Route>
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/lab" element={<Lab />} />
<Route
path="*"
element={<Navigate to="/" replace />} //this is a way to redirect
/>
</Routes>
</BrowserRouter>
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/lab" element={<Lab />} />
<Route
path="*"
element={<Navigate to="/" replace />}
/>
</Routes>
</BrowserRouter>
<Route
path="/signin"
element={
this.props.currentUser ? (
<Navigate to="/" replace />
) : (
<SignInAndSignUpPage />
)
}
/>