1.0.0-alpha.2 • Published 7 years ago
@tivac/router v1.0.0-alpha.2
@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:
- ctx, a shared object available to all handlers of a request
- next(), a function that will invoke any further route handlers.
1.0.0-alpha.2
7 years ago
1.0.0-alpha.1
7 years ago