did-route
did-route is an isomorphic router that returns false when it didn’t handle a request.
Install
$ npm install did-route
Example
var http = var did = // Homedid // Itemdid http
Which would result in the following responses:
$ curl http://localhost:8080> Welcome to the homepage $ curl -X PATCH http://localhost:8080/item/6d80eb0c50b49a5> Updated 6d80eb0c50b49a5 $ curl -iX DELETE http://localhost:8080/item/6d80eb0c50b49a5> HTTP/1.1 405 Method Not Allowed
Browser
did-route also works in the browser with basically the same API. The only differences are that a) did.get
is the only available routing method, and b) route handlers receive just one argument: the params object.
var did = did did did window { var path = windowlocation || '/path/to/page' if !did // Handle 404 } window { var includeQueryAndHash = true if !did // Handle 404 }
Page weight
require('did-route')
compression | size |
---|---|
did-route.js | 2.85 kB |
did-route.min.js | 1.65 kB |
did-route.min.js.gz | 850 B |
Running the tests
$ git clone git@github.com:michaelrhodes/did-route$ cd did-route$ npm install$ npm run test:server$ npm run test:browser