Page components are used for setting loading and error pages.
Loading pages are React components that are displayed while guard middleware is resolving.
The default loading page is null.
They can be set either:
-
globally as the
loadingprop of aGuardProvider -
individually as the
loadingprop of aGuardedRoute
Error pages are React components that are displayed when guard logic fails.
The default error page is null.
They can be set either:
-
globally as the
errorprop of aGuardProvider -
individually as the
errorprop of aGuardedRoute
Typically, error pages will be the same component as a Not Found or 404 page.
Note: If using a React component for your error page, it can receive the error message thrown by a guard function via an error prop.
With strings:
import { GuardProvider } from 'react-router-guards';
<GuardProvider loading="Loading..." error="Not found." />;With React components:
import {
ErrorPageComponentType,
GuardProvider,
LoadingPageComponentType,
} from 'react-router-guards';
const NotFound: ErrorPageComponentType = ({ error }) => (
<div>
<h1>Not found.</h1>
{error && <p>{error}</p>}
</div>
);
const Loading: LoadingPageComponentType = () => (
<div>
<div id="loader" />
</div>
);
// ...
<GuardProvider loading={Loading} error={NotFound} />;