JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 35741
  • Score
    100M100P100Q142806F
  • License MIT

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

Package Exports

  • base-routes

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 (base-routes) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

base-routes NPM version NPM downloads Build Status

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

TOC

Install

Install with npm:

$ npm install base-routes --save

Usage

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

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

API

Example

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

.handle

Handle a middleware method for file.

Params

  • method {String}: Name of the router method to handle. See router methods
  • file {Object}: View object
  • callback {Function}: Callback function
  • returns {undefined}

Example

app.handle('customMethod', file, callback);

.handleOnce

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

app.handleOnce('onLoad', file, callback);

.route

Create a new Route for the given path. Each route contains a separate middleware stack. See the [route API documentation][route-api] for details on adding handlers and middleware to routes.

Params

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

Example

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

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

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

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

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

.handler

Add a router handler method to the instance. Interchangeable with the handlers method.

Params

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

Example

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

.handlers

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

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

You might also be interested in these projects:

  • base-option: Adds a few options methods to base, like option, enable and disable. See the readme… more | homepage
  • base-plugins: Upgrade's plugin support in base applications to allow plugins to be called any time after… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • en-route: Routing for static site generators, build systems and task runners, heavily based on express.js routes… more | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine.… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on May 17, 2016.