A utility for building a list of breadcrumbs from chopped URL's.
npm install --save breadcrumble
var breadcrumble = require('breadcrumble');
breadcrumble.config = require('./breadcrumbs.json');
var crumbs = breadcrumble.match('/users/33/profile');
// [ 'Users', 'ID (33)', 'Profile' ]
func match(path: String, (config: Object))
Breadcrumble will match the given path against an optional config object or the module-global config (see below). This function will return an array of route descriptors for each matching fragments. If your config looks like this
{ key: 'app', someProp: 1, someProp: 2 }
Then the result of breadcrumble.match('/app/')
will be [ { someProp: 1, someProp: 2 } ]
.
var breadcrumble = require('breadcrumble/dist/breadcrumble.min.js');
You can provide your route config in the call to match()
or set the module-global config
with
breadcrumble.config = {...};
The schema for your route configuration is this (only key
is required):
type Route {
key: String!
name: String
hidden: Boolean
routes: [Route]
}
name
: Will be returned with matched path replaced. i.e. if the route descriptor is{ key: ':id', name: 'ID (:id)' }
and path"/33/"
is matched, then in the returned array,name
will be"ID (33)"
. For regexes, use token$0
to replace the first matched group.hidden
: If this is present andtrue
, then this descriptor will not be present in the returned breadcrumbs. Useful if you do not want your root (/
) to appear, for example.
- Fork and make your changes.
- Only run
npm run build
and commit your new dist files on a tag release. - Make sure you run the tests.
- Open a pull request.
- MIT