I have App.js only contains route:
function App() {
return (
<BrowserRouter>
<Routes>
<Route element={<Login />} path="/login"></Route>
<Route element={<NotFound />} path="*"></Route>
<Route element={<PrivateRoutes />}>
<Route element={<Home />} path="/"></Route>
</Route>
</Routes>
</BrowserRouter>
);
}
And my PrivateRoute.js is
function PrivateRoutes() {
const key = sessionStorage.getItem("key")
// I would like to use Axios here to verify if the token is legal
return (
key === "123" ? <Outlet /> : <Navigate to="/login"></Navigate>
)
}
I would like to use Axios to verify if the token is legal, but Axios is asynchronous, so I can not get response and compare with local token.
What should I do ?