72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
/* eslint-disable react-refresh/only-export-components */
|
|
import { lazy } from 'react';
|
|
import type { ComponentType } from 'react';
|
|
import { createBrowserRouter, Navigate } from 'react-router-dom';
|
|
import Layout from '../components/Layout';
|
|
import ProtectedRoute from '../components/ProtectedRoute';
|
|
import Login from '../pages/Login';
|
|
|
|
// Lazy loading admin pages
|
|
const Dashboard = lazy(() => import('../pages/Dashboard'));
|
|
const Users = lazy(() => import('../pages/Users'));
|
|
const Products = lazy(() => import('../pages/Products'));
|
|
const Orders = lazy(() => import('../pages/Orders'));
|
|
const Coupons = lazy(() => import('../pages/Coupons'));
|
|
const Settings = lazy(() => import('../pages/Settings'));
|
|
const Reports = lazy(() => import('../pages/Reports'));
|
|
const Categories = lazy(() => import('../pages/Categories'));
|
|
const Blogs = lazy(() => import('../pages/Blogs'));
|
|
const Wiki = lazy(() => import('../pages/Wiki'));
|
|
const Pets = lazy(() => import('../pages/Pets'));
|
|
const UITexts = lazy(() => import('../pages/UITexts'));
|
|
const Media = lazy(() => import('../pages/Media'));
|
|
const CMS = lazy(() => import('../pages/CMS'));
|
|
const WholesaleApplications = lazy(() => import('../pages/WholesaleApplications'));
|
|
const Videos = lazy(() => import('../pages/Videos'));
|
|
const ContactSubmissions = lazy(() => import('../pages/ContactSubmissions'));
|
|
|
|
export interface AdminRouteConfig {
|
|
path: string;
|
|
component: ComponentType;
|
|
index?: boolean;
|
|
}
|
|
|
|
export const router = createBrowserRouter([
|
|
{
|
|
path: '/login',
|
|
element: <Login />,
|
|
},
|
|
{
|
|
element: <ProtectedRoute />,
|
|
children: [
|
|
{
|
|
path: '/',
|
|
element: <Layout />,
|
|
children: [
|
|
{ index: true, element: <Dashboard /> },
|
|
{ path: 'users/*', element: <Users /> },
|
|
{ path: 'products/*', element: <Products /> },
|
|
{ path: 'orders/*', element: <Orders /> },
|
|
{ path: 'coupons/*', element: <Coupons /> },
|
|
{ path: 'settings/*', element: <Settings /> },
|
|
{ path: 'reports/*', element: <Reports /> },
|
|
{ path: 'categories/*', element: <Categories /> },
|
|
{ path: 'blogs/*', element: <Blogs /> },
|
|
{ path: 'wiki/*', element: <Wiki /> },
|
|
{ path: 'videos/*', element: <Videos /> },
|
|
{ path: 'pets/*', element: <Pets /> },
|
|
{ path: 'ui-texts/*', element: <UITexts /> },
|
|
{ path: 'media/*', element: <Media /> },
|
|
{ path: 'cms/*', element: <CMS /> },
|
|
{ path: 'wholesale/*', element: <WholesaleApplications /> },
|
|
{ path: 'contact/*', element: <ContactSubmissions /> },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '*',
|
|
element: <Navigate to="/" replace />,
|
|
},
|
|
]);
|