The GuardProvider
component is a high-level wrapper for your entire routing solution.
The GuardProvider
provides an API for declaring global guards and loading and error pages that can be used by any GuardedRoute
within its scope:
interface GuardProviderProps {
guards?: GuardFunction[];
ignoreGlobal?: boolean;
loading?: PageComponent;
error?: PageComponent;
}
Prop | Optional | Description |
---|---|---|
guards |
✅ | global guards for all children GuardProvider s and GuardedRoute s |
ignoreGlobal |
✅ | whether to ignore guards set by parent GuardedProvider s |
loading |
✅ | the global loading page for all children |
error |
✅ | the global error page for all children |
See here for more information on how nesting guard providers affects global guards and loading and error pages.
All GuardProvider
s must be wrapped by a Router
component.
const App = () => (
<Router>
<GuardProvider guards={guards} loading={Loading} error={NotFound}>
<GuardedRoute path="/" exact component={Home} />
</GuardProvider>
</Router>
);
Nesting guard providers is useful in case where you may only want a certain subset of routes to have the same guards, loading page, and/or error page.
By nesting guard providers, you can either chain functionality or override that of its parent(s):
Prop | Result |
---|---|
guards |
Overridden if ignoreGlobal is true ; otherwise, guards are appended to the end of the middleware queue. |
loading |
Overridden, if value provided. |
error |
Overridden, if value provided. |