router.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. import UnauthorisedError from './pages/errors/unauthorised-error.tsx'
  6. const router = createBrowserRouter([
  7. // Auth routes
  8. {
  9. path: '/sign-in',
  10. lazy: async () => ({
  11. Component: (await import('./pages/auth/sign-in')).default,
  12. }),
  13. },
  14. {
  15. path: '/sign-in-2',
  16. lazy: async () => ({
  17. Component: (await import('./pages/auth/sign-in-2')).default,
  18. }),
  19. },
  20. {
  21. path: '/sign-up',
  22. lazy: async () => ({
  23. Component: (await import('./pages/auth/sign-up')).default,
  24. }),
  25. },
  26. {
  27. path: '/forgot-password',
  28. lazy: async () => ({
  29. Component: (await import('./pages/auth/forgot-password')).default,
  30. }),
  31. },
  32. {
  33. path: '/otp',
  34. lazy: async () => ({
  35. Component: (await import('./pages/auth/otp')).default,
  36. }),
  37. },
  38. // Main routes
  39. {
  40. path: '/',
  41. lazy: async () => {
  42. const AppShell = await import('./components/app-shell')
  43. return { Component: AppShell.default }
  44. },
  45. errorElement: <GeneralError />,
  46. children: [
  47. {
  48. index: true,
  49. lazy: async () => ({
  50. Component: (await import('./pages/dashboard')).default,
  51. }),
  52. },
  53. {
  54. path: 'tasks',
  55. lazy: async () => ({
  56. Component: (await import('@/pages/tasks')).default,
  57. }),
  58. },
  59. {
  60. path: 'chats',
  61. lazy: async () => ({
  62. Component: (await import('@/pages/chats')).default,
  63. }),
  64. },
  65. {
  66. path: 'apps',
  67. lazy: async () => ({
  68. Component: (await import('@/pages/apps')).default,
  69. }),
  70. },
  71. {
  72. path: 'users',
  73. lazy: async () => ({
  74. Component: (await import('@/components/coming-soon')).default,
  75. }),
  76. },
  77. {
  78. path: 'analysis',
  79. lazy: async () => ({
  80. Component: (await import('@/components/coming-soon')).default,
  81. }),
  82. },
  83. {
  84. path: 'extra-components',
  85. lazy: async () => ({
  86. Component: (await import('@/pages/extra-components')).default,
  87. }),
  88. },
  89. {
  90. path: 'settings',
  91. lazy: async () => ({
  92. Component: (await import('./pages/settings')).default,
  93. }),
  94. errorElement: <GeneralError />,
  95. children: [
  96. {
  97. index: true,
  98. lazy: async () => ({
  99. Component: (await import('./pages/settings/profile')).default,
  100. }),
  101. },
  102. {
  103. path: 'account',
  104. lazy: async () => ({
  105. Component: (await import('./pages/settings/account')).default,
  106. }),
  107. },
  108. {
  109. path: 'appearance',
  110. lazy: async () => ({
  111. Component: (await import('./pages/settings/appearance')).default,
  112. }),
  113. },
  114. {
  115. path: 'notifications',
  116. lazy: async () => ({
  117. Component: (await import('./pages/settings/notifications'))
  118. .default,
  119. }),
  120. },
  121. {
  122. path: 'display',
  123. lazy: async () => ({
  124. Component: (await import('./pages/settings/display')).default,
  125. }),
  126. },
  127. {
  128. path: 'error-example',
  129. lazy: async () => ({
  130. Component: (await import('./pages/settings/error-example'))
  131. .default,
  132. }),
  133. errorElement: <GeneralError className='h-[50svh]' minimal />,
  134. },
  135. ],
  136. },
  137. ],
  138. },
  139. // Error routes
  140. { path: '/500', Component: GeneralError },
  141. { path: '/404', Component: NotFoundError },
  142. { path: '/503', Component: MaintenanceError },
  143. { path: '/401', Component: UnauthorisedError },
  144. // Fallback 404 route
  145. { path: '*', Component: NotFoundError },
  146. ])
  147. export default router