compound icon indicating copy to clipboard operation
compound copied to clipboard

Router matching multiple routes to controllers

Open lucaswxp opened this issue 11 years ago • 1 comments

I have the following routes defined:

exports.routes = function (map) {
    map.all('admin/:controller/:action');
    map.all('admin/:controller/:action/:id');
    map.all(':controller/:action');
    map.all(':controller/:action/:id');
};

When I visit /admin/mycontroller/index, I see in my console that compound is trying to access both:

Params: {"controller":"mycontroller","action":"index"} // this is correct
Params: {"controller":"admin","action":"mycontroller","id":"index"}

But I was expecting only the first to be routed. Is this a bug? Yes, both routes are valid, but only one is supposed to be executed, not every matching route.

lucaswxp avatar Sep 03 '14 16:09 lucaswxp

Looks like you defined your routers incorrect.

Maybe you should use namespace, here is an example:

map.namespace('admin', function (admin) {
        admin.resources('posts', {middleware: basic_auth, except: ['show']}, function (post) {
            post.resources('comments');
            post.get('likes', 'posts#likes')
        });
    });

alexbaumgertner avatar Sep 12 '14 08:09 alexbaumgertner