nxus / router

The Nxus router is an Express compatible web server and router for Nxus applications.
MIT License
0 stars 0 forks source link

Named routes to remove path details from handlers/templates #12

Open loppear opened 7 years ago

loppear commented 7 years ago

In combination with #11 that introduces a realPath helper for mapping internal routes to published routes, it would be helpful to address the number of places in handlers and templates that construct routes.

Proposal

Add router.nameRoute(name, route) or a name optional parameter to router.route to give a route an internal name. Add router.routeNamed(name, [params]) and matching template helper.

Usage Example

router.nameRoute("my-detail", "/path/to/:id")

// in handler
res.redirect(router.routeNamed("my-detail", {id: object.id})

// in template
<a href="<%= routeNamed("my-detail", {id: object.id}) %>">