Add named routes to your view templates
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Hapi Named Routes

Hapi plugin to add named routes to your view templates.


In your view templates, instead of always typing the path in your links, you can now have access to the route name variable. It will just print the path.

How it works:

In your view template you can now access where name is the id of the route.

To name a route you need to pass the config object to the route with the id being defined.


// Route Config
var about = {
    handler: function (request, reply) {
    id: 'about'

// Array of routes for Hapi
routes = [
        method: 'GET',
        path: '/about',
        config: about


Based on the example above you now have access to path.about in your view templates, and will print out the routes path /about.

Handlebars: <a href="{{path.about}}">About</a>

Jade: a(href="#{path.about}") About

Breaking changes

In Hapi 8.0.0 the id property for a route was added to allow a developer to access a route path using server.lookup(). As of hapi-named-routes 0.3.0 we use this id instead of like we previoisly used.


You can see this being used in the Hapi Ninja boilerplate example.