score:0

Accepted answer
const RequireAuth = (): ReactElement => {
  const { token } = storage.getState().authReducer;
  const location = useLocation();
  if (!token) return <Navigate to="/login" state={{ from: location }} />;
  return <Outlet />;
};

export const MainLayout: FC = () => {
  const { t } = useTranslation();

  useEffect(() => {
    console.log('MainLayout:: constructor');
  }, []);

  return (
    <BrowserRouter history={history}>
      <div className="main-wrapper">
        <div className="content-wrapper">
          <div className="main-content">
            <Routes>
              <Route path="/" element={<Login />} />
              <Route path="/login" element={<Login />} />
              <Route element={<RequireAuth />}>
                <Route path="/acceptance" element={<AcceptancePage />} />
                <Route path="/introduction/:page" element={<IntroductionPage />} />
              </Route>
            </Routes>
          </div>
        </div>
      </div>
    </BrowserRouter>
  );
};

Related Query

More Query from same tag