import { type FC, Suspense, lazy, memo, useContext, useEffect, useRef } from 'react'; import { Navigate, Route, Routes } from 'react-router'; import { toast } from 'react-toastify'; import { LoadingSpinner, RequireAuthenticated, RequireUnauthenticated } from 'components'; import { Authentication, AuthenticationContext } from 'contexts/authentication'; import { useI18nContext } from 'i18n/i18n-react'; // Lazy load route components for better code splitting const SignIn = lazy(() => import('SignIn')); const AuthenticatedRouting = lazy(() => import('AuthenticatedRouting')); interface SecurityRedirectProps { readonly message: string; readonly signOut?: boolean; } const RootRedirect: FC = memo( ({ message, signOut = false }) => { const { signOut: contextSignOut } = useContext(AuthenticationContext); const hasShownToast = useRef(false); useEffect(() => { // Prevent duplicate toasts on strict mode or re-renders if (!hasShownToast.current) { hasShownToast.current = true; if (signOut) { contextSignOut(false); } toast.success(message); } // Only run once on mount - using ref to track execution }, []); return ; } ); const AppRouting: FC = memo(() => { const { LL } = useI18nContext(); return ( }> } /> } /> } /> } /> ); }); export default AppRouting;