Skip to content

Latest commit

 

History

History
69 lines (44 loc) · 1.48 KB

page-components.md

File metadata and controls

69 lines (44 loc) · 1.48 KB

Page components

Page components are used for setting loading and error pages.

API

type PageComponent = React.Component | string | boolean | number | null | undefined;

Loading page

Loading pages are React components that are displayed while guard middleware is resolving.

The default loading page is null.

They can be set either:

Error page

Error pages are React components that are displayed when guard logic fails.

The default error page is null.

They can be set either:

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.

Examples

With strings:

<GuardProvider loading="Loading..." error="Not found." />

With React components:

const NotFound = ({ error }) => (
  <div>
    <h1>Not found.</h1>
    <p>{error}</p>
  </div>
);

const Loading = () => (
  <div>
    <div id="loader" />
  </div>
);

<GuardProvider loading={Loading} error={NotFound} />;