@cloudflare/util-route-handler

1.2.15 • Public • Published

cf-util-route-handler

Cloudflare Route Handler Util

Installation

$ npm install cf-util-route-handler

Usage

import {handleRoutes, routeTo} from 'cf-util-route-handler';
import Backbone from 'backbone';

// setup the router
handleRoutes(function(url) {
  Backbone.history.navigate(url, true);
});

// do all the world to make the router work normally
new Backbone.Router({
  routes: {
    ''    : () => console.log('/'),
    hello : () => console.log('/hello'),
    world : () => console.log('/world')
  }
});
Backbone.history.start();

// start routing
routeTo('/');
routeTo('/hello');
routeTo('/world');

A handler looks like this:

handleRoutes(url => {
  takeActionWithUrl(url);
});

Only one handler is allowed to be setup.

routeTo is fire and forget, there's no callback for async transitions, and it does not return anything.

Readme

Keywords

none

Package Sidebar

Install

npm i @cloudflare/util-route-handler

Weekly Downloads

5,707

Version

1.2.15

License

BSD-3-Clause

Unpacked Size

9.59 kB

Total Files

7

Last publish

Collaborators

  • lbarthonet
  • cf-media-manager
  • jacobbednarz
  • celso
  • cf-radar
  • dash_service_account
  • g4brym
  • snigdha34
  • wrangler-publisher
  • marksteyn
  • chiminator
  • sgoodhew_cf
  • terinjokes
  • third774
  • jsteinberger
  • jasnell
  • asapzacy
  • pcostanzo
  • gregbrimble
  • geelen
  • rexscaria
  • dcruz_cf
  • xuranwang
  • jculvey
  • sejoker
  • vasturiano
  • cf-ci-write
  • segments-write
  • thibmeu
  • xortive
  • gurjinder
  • cf-ci2
  • lvalenta
  • worenga