spa-town
v0.1.2
Published
A simple router based on bath
Downloads
42
Readme
spa-town
A simple router based on bath.
Installation
$ npm install spa-town
Usage
import * as assert from 'assert';
import { result, route, router } from 'spa-town';
const router1 = router([
route('root#index', '/'),
route('users#index', '/users'),
route('users#index', '/users/'),
route('users#show', '/users/{id}', { id: /^\w+$/ }),
route('users#show', '/users/{id}/', { id: /^\w+$/ })
], result('root#notfound', {}));
assert.deepEqual(router1('/'), result('root#index', {}));
assert.deepEqual(router1('/users'), result('users#index', {}));
assert.deepEqual(router1('/users/'), result('users#index', {}));
assert.deepEqual(router1('/users/123'), result('users#show', { id: '123' }));
assert.deepEqual(router1('/users/123/'), result('users#show', { id: '123' }));
assert.deepEqual(router1('/no-match'), result('root#notfound', {}));