@curi/route-active

Installation

The package can be installed through npm (you need to have Node & NPM installed).

npm install @curi/route-active

Prefer inline scripts? A full (.umd.js) and minified (.min.js) script is available for every version through Unpkg. You can access the package's exports through window.CuriRouteActive.

About

The @curi/route-active package determines whether a route is "active" by comparing it to the current response. This can be restricted to complete matches or allow partial matches so that locations that represent an ancestor of the current location are also considered "active".

API

active

A function to create the active route interaction. When you create your router, the result is passed to the router using the `route` option, which will add an active() function to the router's route interactions.

The interaction returns a boolean: true when a route is "active" (it matches the response's location) and false when it does not.

import { curi } from '@curi/router';
import active from '@curi/route-active';

const router = curi(history, routes, {
  route: [active()]
});

Arguments

argumentdescription
namethe name of the route to check if it is active
responsethe response to check the route against.
paramsany route params for the route that is being checked
partialwhen true, ancestor routes can be considered active. (default false)
const isActive = router.route.active(
  'Some Route',
  response,
  { id: 10 },
  false
);