All files / src/app router.tsx

95.12% Statements 39/41
100% Branches 0/0
95% Functions 38/40
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168                        1x                               2x         1x       1x       1x       1x               1x                     1x 1x           1x 1x                           1x         1x         1x 1x           1x 1x                     1x 1x           1x 1x           1x 1x               1x         1x 1x           1x 1x           1x                    
import { createBrowserRouter } from 'react-router-dom'
 
 
import { AppShellLayout } from './routes/AppShellLayout'
import { NotFoundRoute } from './routes/NotFoundRoute'
import { ProtectedLayout } from './routes/ProtectedLayout'
import { RouteErrorRoute } from './routes/RouteErrorRoute'
import { RouteHydrateFallback } from './routes/RouteHydrateFallback'
 
// Route-level code splitting: each feature page (and its forms, dialogs,
// API hooks) only downloads when a user actually navigates there, instead
// of all shipping in the single ~721KB bundle Vite warns about on build.
export const router = createBrowserRouter([
  {
    hydrateFallbackElement: <RouteHydrateFallback />,
    // Na raiz, para cobrir toda rota filha. Sem isto o React Router mostra a
    // própria tela de desenvolvimento — "Unexpected Application Error!" mais o
    // stack — ao usuário final, e o ErrorBoundary do App.tsx nunca vê o caso:
    // erro de rota é tratado pelo roteador antes de subir para o React.
    errorElement: <RouteErrorRoute />,
    children: [
      {
        // The landing page for a visitor, the dashboard for someone signed in
        // (the route itself decides, without a request when there is no
        // session — see LandingRoute). Until 2026-10 `/` belonged to the
        // session layout and sent every visitor to /login, so nothing of the
        // app could be seen without an account.
        index: true,
        lazy: () => import('@/features/landing/routes/LandingRoute').then((m) => ({ Component: m.LandingRoute })),
      },
      {
        // Keep the shared shell mounted when switching between public routes.
        // Lazy loading keeps the photograph and auth UI out of the app entry.
        lazy: () => import('@/features/auth/components/AuthLayout').then((m) => ({ Component: m.AuthLayout })),
        children: [
          {
            path: '/auth/google/complete',
            lazy: () => import('@/features/auth/routes/GoogleCompleteRoute').then((m) => ({ Component: m.GoogleCompleteRoute })),
          },
          {
            path: '/login',
            lazy: () => import('@/features/auth/routes/LoginRoute').then((m) => ({ Component: m.LoginRoute })),
          },
          {
            path: '/register',
            lazy: () => import('@/features/auth/routes/RegisterRoute').then((m) => ({ Component: m.RegisterRoute })),
          },
          {
            // The invite preview shares the shell and stays outside
            // ProtectedLayout — the preview has to render for a logged-out
            // visitor, which is the whole audience of an invite link (see
            // InviteRedeemRoute.tsx).
            path: '/invites/:code',
            lazy: () => import('@/app/routes/InviteRedeemRoute').then((m) => ({ Component: m.InviteRedeemRoute })),
          },
        ],
      },
      {
        // Public on purpose, and lazy like every other route: a privacy policy
        // that demands a login to be read does not do the thing it exists to
        // do. Both paths render the same component — the structure is shared
        // and only the copy differs.
        path: '/privacidade',
        lazy: () =>
          import('@/features/legal/routes/LegalDocumentRoute').then((m) => ({
            Component: () => <m.LegalDocumentRoute documentId="privacy" />,
          })),
      },
      {
        path: '/termos',
        lazy: () =>
          import('@/features/legal/routes/LegalDocumentRoute').then((m) => ({
            Component: () => <m.LegalDocumentRoute documentId="terms" />,
          })),
      },
      {
        // Pathless: `/` is the landing route above, and a layout with its own
        // index child would match `/` a second time.
        element: <ProtectedLayout />,
        children: [
          {
            element: <AppShellLayout />,
            children: [
              {
                path: 'dashboard',
                lazy: () =>
                  import('@/features/babies/routes/DashboardRoute').then((m) => ({ Component: m.DashboardRoute })),
              },
              {
                path: 'vaccines',
                lazy: () =>
                  import('@/features/vaccines/routes/VaccinesRoute').then((m) => ({ Component: m.VaccinesRoute })),
              },
              {
                path: 'vaccines/:babyId/card',
                lazy: () =>
                  import('@/features/vaccines/routes/VaccinationCardRoute').then((m) => ({
                    Component: m.VaccinationCardRoute,
                  })),
              },
              {
                path: 'appointments',
                lazy: () =>
                  import('@/features/appointments/routes/AppointmentsRoute').then((m) => ({
                    Component: m.AppointmentsRoute,
                  })),
              },
              {
                // In the menu; `/plano-de-saude` below is not, and the asymmetry survived the
                // bottom bar it was first argued from. It used to be arithmetic — seven targets
                // dividing 320px — and now it is only what a section is *for*: a professional is
                // looked up as often as an appointment is, while a card number is looked up at a
                // clinic desk, from the child's profile, and does not earn a permanent row.
                path: 'profissionais',
                lazy: () =>
                  import('@/features/specialists/routes/SpecialistsRoute').then((m) => ({
                    Component: m.SpecialistsRoute,
                  })),
              },
              {
                path: 'plano-de-saude',
                lazy: () =>
                  import('@/features/babies/routes/HealthPlanRoute').then((m) => ({
                    Component: m.HealthPlanRoute,
                  })),
              },
              {
                path: 'medications',
                lazy: () =>
                  import('@/features/medications/routes/MedicationsRoute').then((m) => ({
                    Component: m.MedicationsRoute,
                  })),
              },
              {
                // Reads the appointments and owns no endpoint of its own: weight and height are
                // recorded on the visit that took them (see growth.selectors.ts).
                path: 'crescimento',
                lazy: () =>
                  import('@/features/growth/routes/GrowthRoute').then((m) => ({ Component: m.GrowthRoute })),
              },
              {
                path: 'milestones',
                lazy: () =>
                  import('@/features/milestones/routes/MilestonesRoute').then((m) => ({
                    Component: m.MilestonesRoute,
                  })),
              },
              {
                path: 'notifications',
                lazy: () =>
                  import('@/features/notifications/routes/NotificationsRoute').then((m) => ({
                    Component: m.NotificationsRoute,
                  })),
              },
              {
                path: 'profile',
                lazy: () =>
                  import('@/features/profile/routes/ProfileRoute').then((m) => ({ Component: m.ProfileRoute })),
              },
            ],
          },
        ],
      },
      { path: '*', element: <NotFoundRoute /> },
    ],
  },
])