I've been trying to make a 404 not found page and redirect all non-matched routes there, currently configured with whole context as:
<Switch>
<Route path="/faq" component={FAQ}></Route>
<Route path="/404">
<NotFound />
</Route>
<Suspense fallback={<div>Loading ...</div>}>
<Route path="/admin" component={AdminModule}></Route>
</Suspense>
<Redirect exact={true} from="*" to="/404" />
</Switch>
Tried various other solutions that I've found in the docs but none of them seem to work, is this by design or a bug? if it's by design, what is the design? It seems like a use case that every single app out there would need.
You should not usw Suspense inside Switch. Your Switch must be wrapped by Suspense component.
<Suspense fallback={<div>Loading ...</div>}>
<Switch>
<Route path="/faq" component={FAQ}></Route>
<Route path="/404">
<NotFound />
</Route>
<Route path="/admin" component={AdminModule}></Route>
<Redirect exact={true} from="*" to="/404" />
</Switch>
</Suspense>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With