I'm using "@reach/router": "^1.2.1"
and in my App.js
file I've got a fallback component to show while my routes are loading:
<React.Suspense fallback={<MainLandingPageLoadingScreen />}>
<Router>
<MainLandingPage path="/" />
<AnotherLandingPage path="/coolbeans" />
<NotFound default />
</Router>
</React.Suspense>
But depending on the route, I want to use a different loading component as the fallback, so something like:
<Router>
<React.Suspense fallback={<AnotherLandingPageLoadingScreen />}>
<MainLandingPage path="/" />
<NotFound default />
</React.Suspense>
<React.Suspense fallback={<AnotherLandingPageLoadingScreen />}>
<AnotherLandingPage path="/coolbeans" />
</React.Suspense>
</Router>
This won't work because Router needs to be wrapped around Suspense, instead of this way around. But if I split it like below then the second Router list doesn't get picked up and the route is a 404:
<React.Suspense fallback={<MainLandingPageLoadingScreen />}>
<Router>
<MainLandingPage path="/" />
<NotFound default />
</Router>
</React.Suspense>
<React.Suspense fallback={<AnotherLandingPageLoadingScreen />}>
<Router>
<AnotherLandingPage path="/coolbeans" />
</Router>
</React.Suspense>
What is the correct way to provide a fallback component on a routing level?