Currently, Y.Router#route() only accepts a string or regex path as its first argument, it then processes that into a route config object. It would also be useful if Router accepted an already processed route config object provided by the caller.
To coordinate routes between the server (like Express) and client, it's important to make sure subtle things like whether to use optional trailing slashes are preserved. The best way to do this is to provide Y.Router with the same regex path that's used server side. The problem in doing so is when a regex path is used, you have to use unnamed params in route handlers. Allowing the following would resolve this issue:
var routeConfigFromServer = {
path : '/posts/:postId',
keys : ['postId'],
regexp: /^\/posts\/(?:([^\/]+?))\/?$/i
};
var router = new Y.Router();
router.showPost = function (req, res, next) {
// ...
};
router.route(routeConfigFromServer, 'showPost');
This would allow keys to be supplied with the regexp, giving the route handlers named params.
Currently,
Y.Router#route()only accepts a string or regexpathas its first argument, it then processes that into a route config object. It would also be useful if Router accepted an already processed route config object provided by the caller.To coordinate routes between the server (like Express) and client, it's important to make sure subtle things like whether to use optional trailing slashes are preserved. The best way to do this is to provide
Y.Routerwith the same regex path that's used server side. The problem in doing so is when a regex path is used, you have to use unnamed params in route handlers. Allowing the following would resolve this issue:This would allow
keysto be supplied with theregexp, giving the route handlers named params.