Classes: RouteRequirement

RouteRequirement


new RouteRequirement(name, childRequirements, test, onFail)

A helper class to define a requirement that is needed to enter a route. Instances of this class can be passed to Route components using the requirements prop

Parameters:
Name Type Description
name string

A name used for debugging purposes

childRequirements Array.<RouteRequirement>

An array of other RouteRequirement instances. The child requirements will always be checked before this one.

test function

A function that checks if the requirement is met. Receives the following parameters:

  • getState The redux getState function
  • renderProps the renderProps returned by react router based on the current route
  • dispatch The redux dispatch function
  • accountState The cookie or redux state Can return a boolean that indicates if the requirement is met, or a Promise that resolves with a boolean.
onFail function

A function that will be executed when the requirement is not met. Receives the following parameters:

  • state The redux getState function
  • renderProps the renderProps returned by react router based on the current route
  • callbacks An object with these properties:
    • redirect(path) A function that will redirect to the given path
    • redirectToLogin() A function that will redirect to the login endpoint
Source: