AltoRouter icon indicating copy to clipboard operation
AltoRouter copied to clipboard

Support for route groups, namespaces and constraints

Open koenpunt opened this issue 8 years ago • 1 comments

Because there have been multiple issues and/or pull requests about route groups, namespaces and constraints, here a central issue to the discuss the requirements for such a feature.

I think nested function would be a nice way to group routes.

For example:

$router->group(array('path' => '/prefix'), function($router) {
  #=> matches /prefix/index
  $router->map('GET', '/index', 'some_action');

  $router->group(array('path' => '/admin'), function($router) {
    #=> matches /prefix/admin/index
    $router->map('GET', '/index', 'some_action');
  });
});

Or more generic with some sort of middleware:

$router->group(function($method, $route, $target, $name = null) {
  // this method is called for all routes in a group
  return [$method, '/admin' . $route, $target, $name];
}, function($router) {
  #=> matches /admin/index
  $router->map('GET', '/index', 'some_action');
});

But more suggestions are welcome.


cc: #52 #83 #149

koenpunt avatar Jun 21 '16 22:06 koenpunt

I think it would be cool to add support for this, but not super sold on it yet as it's also a fairly trivial thing to do yourself (as you did already, I believe).

What other group types will we allow besides path prefixes. Subdomain? HTTP methods? If we're just supporting path prefixes, do we need the configuration array at all?

From first sight, I do prefer the first proposed syntax over the second one.

dannyvankooten avatar Jun 22 '16 08:06 dannyvankooten