Named routes for Express.
Simple named routes for Express.
The following methods will print deprecation messages when used as extending the
app variable is error prone and doesn't really provide a better interface,
especially when calling routes from controllers (
req.app.p('login') is a lot
more verbose than simply requiring
Install via npm
$ npm install path-finder
Extend your Express
var express = require'express';var app = express;var pathFinder = require'path-finder';pathFinderextendapp;
// Standard Express routing does not changeappget'/users'// Passing in a name stores the pathappget'/home' 'home'apppost'/user/:id' 'user' ;// Paths can be accessed viapathFinderpath'home'; //-> '/home'pathFinderpath'user' id: 10; //-> '/user/10'// Passing in additional options adds them to the query stringpathFinderpath'home' p: 1; //-> '/home?p=1'// Ad-hoc paths can also be definedpathFinderaddPath'promotions' '/promotions';pathFinderpath'promotions'; //-> '/promotions'
p method is also made available to views
a(href=p('promotions'))| View our promotions
Clone the repo
$ git clone firstname.lastname@example.org:davidcornu/path-finder.git
$ npm install
Run the tests
$ npm test