I'm trying to implement into my lazy loading private routing so I can guard my app but when I try to navigate to a route using my private routing it's redirecting me to a blank page without any errors. What did I do wrong? here is my code:
App.js:
function App() {
return (
<>
<div>
<BrowserRouter>
<main>
<Routes>
<Route
path="/"
element={
<Suspense fallback={<>...</>}>
<HomePage />
</Suspense>
}
/>
<Route path="/purchaseOrders" element={<PrivateRoute />}>
<Route
path="/purchaseOrders"
element={
<Suspense fallback={<>...</>}>
<PurchaseOrders />
</Suspense>
}
/>
</Route>
<Route path="*" element={<HomePage />} />
</Routes>
</main>
</BrowserRouter>
</div>
</>
);
}
privateroute.js:
const PrivateRoute = () => {
const auth = localStorage.getItem("token") == null ? false : true;
return auth ? <Outlet /> : <Link to={Config.loginUrl} />;
};
export default PrivateRoute;