trie-router
trie-router copied to clipboard
What about generating url for the route?
Is it possible to generate url for specific route not to hardcode them in templates?
not sure what you mean. example?
Something like this:
app.get('post', '/post/:id', function *() {...});
// Generates url for post with id = 1
var url = app.pathForRoute('post', { id: 1 });
// ==> '/post/1'
oh i c. i see a lot of edge cases with that. not totally against it though, but i would never use it.
Why not? Almost every serious web framework has such feature. It's very useful and helps you follow DRY principle. I was very surprised that even Express doesn't have this feature...
i see a lot of edge cases with that
What edge cases do you mean?
yeah i've never seen the need for it. easier just to do '/post/' + id.
just stuff like routes without names, not having all the names defined, etc. i could making the definitions stricter and throw if not all the names are provided in the helper or something.
Needs for it are simple:
- You don't need to think about url parts encoding.
- If route url changes you will not need to change it in all the templates it is used in.
- Ability to connect your sub-application to some prefixed path (e.g. "app-admin" to "/admin") without changing any urls in "app-admin" templates.
+1