Как-то так:
import React from 'react';
const Page1 = React.lazy(() => import('./Page1.tsx'));
const Page2 = React.lazy(() => import('./Page2.tsx'));
export default function App() {
const pathname = location?.pathname;
let PageComponent: any | null = null;
if (pathname === '/page-1') {
PageComponent = Page1;
}
if (pathname === '/page-2') {
PageComponent = Page2;
}
if (!PageComponent) {
return <>Main page</>;
}
return <React.Suspense fallback={<>Loading...</>}>
<PageComponent/>
</React.Suspense>;
}
|