cds-snc / node-starter-app

Quick start application setup.... because you have to start somewhere.
MIT License
5 stars 3 forks source link

route helper in views #105

Closed maxneuvians closed 4 years ago

maxneuvians commented 4 years ago

Currently there seems to be no way to get a url for a known route in a view. The current route is accessible through {{ route }} but you are unable to get the route for anything else, ex. {{ route.get("logout").url }} is not a thing.

maxneuvians commented 4 years ago

Recommend doing something like this:

  1. Add a global function to nunjucks ex. .addGlobal('getRoute', (name) => app.routes.get(name))
  2. Invoke it like this: <a href="{{getRoute("logout").path[locale]}}">{{ __("Logout") }}</a>
maxneuvians commented 4 years ago

Looks like routePath("logout") already exists :tada: