Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

bouzuya/spa-town

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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', {}));

Badges

npm version Travis CI

License

MIT

Author

bouzuya <m@bouzuya.net> (http://bouzuya.net)