News for hackers. Stuff that matters.
Re:Show HN: Simple express-like routing for front-end by franciscop on Wednesday August 17, 2016 @02:57AM (#12302923)
It was initially a Regex-only project so it was quite different. Then I added path-to-regex and forgot to check if there was some library out there similar so now they are quite similar.

However I can see a couple of important differences:

1. The parameters are passed to the callback in pagex which makes it cleaner:

    pagex('/users/:id/:frag?', function(id, frag = 'profile'){ ... });
While with page.js you have to retrieve them manually:

    pagex('users/:id/:frag?', function(ctx){ var id = ctx[0], frag = ctx[1] });
2. You can negate the url. For instance, if you want something to run in all pages except in the users page:

    pagex('/users', true, function(){ ... });
3. [undocumented, not-official] There is a before and after catch-all which can be useful for debugging, analytics or similar
Re:Show HN: Simple express-like routing for front-end by JasonSage on Wednesday August 17, 2016 @05:54AM (#12303463)
Quick tip, instead of passing true here, having an options object improves readability. As somebody who's never seen it before, the following does the opposite of what I expect:

  pagex('/users', true, function(){ ... });
But _this_ is more readable—communicates exactly what I need to know, and requires no previous knowledge of the library:

  pagex('/users', { negate: true }, function(){ ... });
Thanks for sharing your library, I love how you've put the ergonomics of use first. :)
Re:Show HN: Simple express-like routing for front-end by franciscop on Wednesday August 17, 2016 @11:58AM (#12305644)
I am totally going to do that, but haven't got around to do it yet. This will also add a bit of flexibility (much needed) about how to pass options.