route.jsx
======================================================
import React, { lazy, Suspense } from "react";
import { useSelector } from "react-redux";
import { Outlet, Route, Routes, useNavigate } from "react-router-dom";
import Loading from "@components/customers/shared/Loading";
import Error from "@pages/customer/error/Error";
const Home = lazy(() => import("@pages/Customer/Home"));
const Profile = lazy(() => import("@pages/Customer/Profile"));
const Checkout = lazy(() => import("@pages/Customer/Checkout"));
const UnauthorizedError = lazy(() => import("@pages/Customer/error/UnauthorizedError"));
const CustomerRoute = () => {
const isAuthenticated = useSelector((state) => state.auth.isAuthenticated);
const PrivateRoute = ({ children }) => {
return isAuthenticated ? children : <UnauthorizedError />;
};
return (
<Routes>
<Route
element={
<Suspense fallback={<Loading />}>
<CustomerLayout />
</Suspense>
}
>
<Route path="/" element={<Home />} />
<Route
path="/profile"
element={
<PrivateRoute>
<Profile />
</PrivateRoute>
}
/>
<Route path="*" element={ <Error
statusCode={404}
title={"Page Not Found"}
message="Sorry, the page you are looking for could not be found.
Please check the URL or go back to the previous page."
/>} />
</Route>
</Routes>
);
};
export default CustomerRoute;
function CustomerLayout() {
return (
<>
<div className="flex flex-col min-h-screen bg-secondary">
<header className="">
<Nav />
</header>
<main className="flex-grow container mx-auto ">
<Outlet />
</main>
{
}
</div>
</>
);
}