# base-routes

> Plugin for adding routes support to your `base` application. Requires templates support to work.

Latest version **1.0.1** (published 2017-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install base-routes
pnpm add base-routes
yarn add base-routes
bun add base-routes
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-08-07 |
| First published | 2015-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | api, app, application, base, base-plugin, baseplugin, building-blocks, create, framework, middleware, plugin, plugins, router, routes, routing, tool, toolkit, tools |

## Links

- npm: https://www.npmjs.com/package/base-routes
- Repository: https://github.com/node-base/base-routes
- Issues: https://github.com/node-base/base-routes/issues
- npm.io page: https://npm.io/package/base-routes

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^2.6.8
- [en-route](https://npm.io/package/en-route.md) ^1.0.1
- [is-valid-app](https://npm.io/package/is-valid-app.md) ^0.3.0
- [template-error](https://npm.io/package/template-error.md) ^0.1.2

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-08-07
- 1.0.0 — 2017-08-07
- 0.2.2 — 2016-07-09
- 0.2.1 — 2016-06-07
- 0.2.0 — 2016-05-17
- 0.1.0 — 2015-11-29

## README

# base-routes [![NPM version](https://img.shields.io/npm/v/base-routes.svg?style=flat)](https://www.npmjs.com/package/base-routes) [![NPM monthly downloads](https://img.shields.io/npm/dm/base-routes.svg?style=flat)](https://npmjs.org/package/base-routes) [![NPM total downloads](https://img.shields.io/npm/dt/base-routes.svg?style=flat)](https://npmjs.org/package/base-routes) [![Linux Build Status](https://img.shields.io/travis/node-base/base-routes.svg?style=flat&label=Travis)](https://travis-ci.org/node-base/base-routes)

> Plugin for adding routes support to your `base` application. Requires templates support to work.

- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [About](#about)

_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save base-routes
```

## Usage

Register the plugin with your [base](https://github.com/node-base/base) application.

```js
var routes = require('base-routes');
var Base = require('base-app');

var app = new Base();
app.use(routes());
```

## API

### [.Router](index.js#L23)

The `Router` and `Route` classes are on the `app` instance, in case they need to be accessed directly.

**Example**

```js
var router = new app.Router();
var route = new app.Route();
```

### [.handle](index.js#L54)

Handle middleware `method` for the given `file`.

**Params**

* `methodName` **{String}**: Name of the router method to handle.
* `file` **{Object}**: View object
* `next` **{Function}**: Callback function
* `returns` **{undefined}**

**Example**

```js
app.handle('methodName', file, next);
```

### [.handleOnce](index.js#L114)

Run the given middleware handler only if the file has not already been handled by `method`.

**Params**

* `method` **{Object}**: The name of the handler method to call.
* `file` **{Object}**
* `returns` **{undefined}**

**Example**

```js
app.handleOnce(method, file, callback);
// example
app.handleOnce('onLoad', file, callback);
```

### [.route](index.js#L200)

Create a new Route for the given path. Each route contains a separate middleware stack. See the [en-route](https://github.com/jonschlinkert/en-route) API documentation for details on adding handlers and middleware to routes.

**Params**

* `path` **{String}**
* `returns` **{Object}**: Returns the instance for chaining.

**Example**

```js
app.create('posts');
app.route(/blog/)
  .all(function(file, next) {
    // do something with file
    next();
  });

app.post('whatever', {path: 'blog/foo.bar', content: 'bar baz'});
```

### [.param](index.js#L228)

Add callback triggers to route parameters, where `name` is the name of the parameter and `fn` is the callback function.

**Params**

* `name` **{String}**
* `fn` **{Function}**
* `returns` **{Object}**: Returns the instance for chaining.

**Example**

```js
app.param('title', function(view, next, title) {
  //=> title === 'foo.js'
  next();
});

app.onLoad('/blog/:title', function(view, next) {
  //=> view.path === '/blog/foo.js'
  next();
});
```

### [.all](index.js#L252)

Special route method that works just like the `router.METHOD()` methods, except that it matches all verbs.

**Params**

* `path` **{String}**
* `callback` **{Function}**
* `returns` **{Object}** `this`: for chaining

**Example**

```js
app.all(/\.hbs$/, function(view, next) {
  // do stuff to view
  next();
});
```

### [.handler](index.js#L274)

Add a router handler method to the instance. Interchangeable with the [handlers](#handlers) method.

**Params**

* `method` **{String}**: Name of the handler method to define.
* `returns` **{Object}**: Returns the instance for chaining

**Example**

```js
app.handler('onFoo');
// or
app.handler(['onFoo', 'onBar']);
```

### [.handlers](index.js#L293)

Add one or more router handler methods to the instance.

**Params**

* `methods` **{Array|String}**: One or more method names to define.
* `returns` **{Object}**: Returns the instance for chaining

**Example**

```js
app.handlers(['onFoo', 'onBar', 'onBaz']);
// or
app.handlers('onFoo');
```

## About

### Related projects

You might also be interested in these projects:

* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality node.js applications, using plugins like building blocks")
* [en-route](https://www.npmjs.com/package/en-route): Routing for static site generators, build systems and task runners, heavily based on express.js routes… [more](https://github.com/jonschlinkert/en-route) | [homepage](https://github.com/jonschlinkert/en-route "Routing for static site generators, build systems and task runners, heavily based on express.js routes but works with file objects. Used by Assemble, Verb, and Template.")
* [gulp-routes](https://www.npmjs.com/package/gulp-routes): Add middleware to run for specified routes in your gulp pipeline. | [homepage](https://github.com/assemble/gulp-routes "Add middleware to run for specified routes in your gulp pipeline.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 07, 2017._

---
_Source: https://npm.io/package/base-routes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
