Side Effects

Explanation

Side effects are observer functions that are run when a new response is created. They are called after other response handlers (observers that were set using router.observe() and one time functions that were set using router.once()). They receive the new response and an object with information about the navigation.

Side effect functions are registered when creating a router using the sideEffects property of the options object.

import { curi } from '@curi/router';
import mySideEffect from './mySideEffect';

const router = curi(history, routes, {
  sideEffects: [mySideEffect]
});

Live Demo

Use the three buttons at the top of the Sandbox to toggle view modes. Clicking the menu button in the top left corner opens a menu to switch between files.

On GitHub

If you want to run this code locally, the source code is available on GitHub here.