Skip to content

Router should accept a route config object in addition to a string or regex path #1067

Description

@ericf

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions