I need to pass props to the lazy components.
const A = React.lazy(() => import("./A"));
function App() {
return (
<Suspense fallback={<GlobalLoader />}>
<Routes>
<Route path="/s/:name" element={<ValidateName />} />
<Route path="/s" element={<Page fullsize={true}><A name='default'/></Page>} />
<Route path="*" element={<Navigate replace to='/s' />} />
</Routes>
</Suspense>
)
}
const Validatename = () => {
const {name} = useParams();
let allowedValues =[{'name':a, ... },{'name':b, ... },{'name':c, ... }]
let validValue = allowedValues.filter((i)=>i.name === name);
let isValid = (validValue > 0);
if(!isValid) return <Navigate replace to =='/s'>
return <Page fullSize={true}><A name={name}/></Page>
}
Edit:
- Desired outcome: Lazy Loading for Component A.
- Component A is initialised with either 'default' value or value passed in URL i.e. 'name'
- Which value to pass is decided by ValidateName Component and default route /s.
Problem: How to pass prop 'name' in A so that it can be loaded lazily.