router.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { createBrowserRouter } from 'react-router-dom'
  2. import GeneralError from './pages/errors/general-error'
  3. import NotFoundError from './pages/errors/not-found-error'
  4. import MaintenanceError from './pages/errors/maintenance-error'
  5. const router = createBrowserRouter([
  6. // Auth routes
  7. {
  8. path: '/sign-in',
  9. lazy: async () => ({
  10. Component: (await import('./pages/auth/sign-in')).default,
  11. }),
  12. },
  13. {
  14. path: '/sign-in-2',
  15. lazy: async () => ({
  16. Component: (await import('./pages/auth/sign-in-2')).default,
  17. }),
  18. },
  19. {
  20. path: '/sign-up',
  21. lazy: async () => ({
  22. Component: (await import('./pages/auth/sign-up')).default,
  23. }),
  24. },
  25. {
  26. path: '/forgot-password',
  27. lazy: async () => ({
  28. Component: (await import('./pages/auth/forgot-password')).default,
  29. }),
  30. },
  31. // Main routes
  32. {
  33. path: '/',
  34. lazy: async () => {
  35. let AppShell = await import('./components/app-shell')
  36. return { Component: AppShell.default }
  37. },
  38. errorElement: <GeneralError />,
  39. children: [
  40. {
  41. index: true,
  42. lazy: async () => ({
  43. Component: (await import('./pages/dashboard')).default,
  44. }),
  45. },
  46. {
  47. path: 'settings',
  48. lazy: async () => ({
  49. Component: (await import('./pages/settings')).default,
  50. }),
  51. errorElement: <GeneralError />,
  52. children: [
  53. {
  54. index: true,
  55. lazy: async () => ({
  56. Component: (await import('./pages/settings/profile')).default,
  57. }),
  58. },
  59. {
  60. path: 'account',
  61. lazy: async () => ({
  62. Component: (await import('./pages/settings/account')).default,
  63. }),
  64. },
  65. {
  66. path: 'appearance',
  67. lazy: async () => ({
  68. Component: (await import('./pages/settings/appearance')).default,
  69. }),
  70. },
  71. {
  72. path: 'notifications',
  73. lazy: async () => ({
  74. Component: (await import('./pages/settings/notifications'))
  75. .default,
  76. }),
  77. },
  78. {
  79. path: 'display',
  80. lazy: async () => ({
  81. Component: (await import('./pages/settings/display')).default,
  82. }),
  83. },
  84. {
  85. path: 'error-example',
  86. lazy: async () => ({
  87. Component: (await import('./pages/settings/error-example'))
  88. .default,
  89. }),
  90. errorElement: <GeneralError className='h-[50svh]' minimal />,
  91. },
  92. ],
  93. },
  94. ],
  95. },
  96. // Error routes
  97. { path: '/500', Component: GeneralError },
  98. { path: '/404', Component: NotFoundError },
  99. { path: '/503', Component: MaintenanceError },
  100. // Fallback 404 route
  101. { path: '*', Component: NotFoundError },
  102. ])
  103. export default router