JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q53129F
  • License ISC

Express like routing for hyperHTML

Package Exports

  • hyperhtml-app

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hyperhtml-app) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hyperhtml-app

Express like routing for hyperHTML

License: ISC Build Status donate

Minimalistic API

This project uses path-to-regexp module, the official Express JS path parser, and it combines it with an Express like API, mixing in the ease of page.js callbacks.

Based on the tiny, server side compatible, onpushstate module, this module has been created to be an ideal companion for the viperHTML tech fam.

API

  • app.get('/path/:user', callback) to react on paths and trap ctx.params such user or others.
  • app.use(path, callback) to add a generic middleware (similar to app.get but it accepts an array of paths)
  • app.delete(path, callback) to remove a specific callback
  • app.param(name, callback) to react once upfront whenever a specific parameter is passed along.
  • app.navigate(pathname) to push state and navigate to a different URL via standard History API. If the pathname and the search string are the same, it'll trigger a samestate type event (as opposite of popstate and pushstate). If there is a second options parameter and it has a replace or replaceState truthy property, it will not trigger a navigation event but it will replace the latest history with the current URL (shortcut for history.replaceState(...)).

Callbacks

Every callback will be invoked with a generic context object, a next function to invoke once everything is OK, and in case of app.param(name, fn) the value, as third argument, for the specified parameter.

var app = require('hyperhtml-app');
app.get('/', function (ctx) {
  console.log('Welcome');
});
app.use('/:user', function (ctx, next) {
  console.log(ctx.params);
});
app.param('user', function (ctx, next, name) {
  console.log(name); // hyper
});
app.navigate('/hyper');

Compatibility

You can test this library live.

The only relatively modern features your target browser should support are both URL and History API.

You can use polyfill.io link in case you need these polyfills.