@tivac/router

1.0.0-alpha.2 • Public • Published

@tivac/router

A very-simple router, inspired by page.js.

(You probably want to use page.js, honestly. This is just me experimenting!)

Usage

Include in a <script> tag

<script src="https://unpkg.com/router/dist/router.umd.js></script>

Or with import

import router from "router";

Or with require

const router = require("router");

API

router(path, callback[, callback ...])

Create a route mapping path to callback. See Route Callbacks for a description of the signature.

Returns the same router instance for optional chaining.

path supports /:params as well as * or /path/* style wildcards. No regex stuff though.

router.go(path, fn)

Begin route matching for a path. fn will be called when all matched route handlers are complete.

router.unknown(fn)

Define a fn that will be called when a route handler cannot be found.

Route Callbacks

Route callbacks are passed two arguments:

  1. ctx, a shared object available to all handlers of a request
  2. next(), a function that will invoke any further route handlers.

Dependents (0)

Package Sidebar

Install

npm i @tivac/router

Weekly Downloads

0

Version

1.0.0-alpha.2

License

MIT

Unpacked Size

28.3 kB

Total Files

9

Last publish

Collaborators

  • tivac