routes icon indicating copy to clipboard operation
routes copied to clipboard

Second route callback dont work in similar routes

Open websharik opened this issue 4 years ago • 6 comments

I have routes: "/flight/:city/:country" - From city to country "/flight/:country/:city" - From country to city On callback i check params and do somthing or nothing.

Second route callback dont work.

websharik avatar Jan 28 '21 11:01 websharik

AltoRouter match return only first found route.

websharik avatar Jan 29 '21 11:01 websharik

@websharik I think we'll need a bit more here to describe the issue in order to investigate and resolve

jarednova avatar Feb 01 '21 16:02 jarednova

I resolve this problem localy in my project, now i already sent pull request to altorouter (on accepted, your next).

Problem is - callback works only on first match route. Because AltoRouter return first found route (on similar route, AltoRouter must return array of found routes) and "Upstatement/routes" accept only one route, but must accept array of routes and call callback per every founded route.

Your can look my forks (similar-fix branch). routes AltoRouter

websharik avatar Feb 01 '21 20:02 websharik

Routes::map('test/:value_low', function($params) {
    if($params["value_low"] <= 10) echo "low";
});
Routes::map('test/:value_hight', function($params) {
    if($params["value_hight"] > 10) echo "hight";
});

localhost/test/8/ low localhost/test/16/ because second callback not called

websharik avatar Feb 01 '21 20:02 websharik

Routes::map('test/:value_low', function($params) {
    if($params["value_low"] <= 10) echo "low";
});
Routes::map('test/:value_hight', function($params) {
    if($params["value_hight"] > 10) echo "hight";
});

localhost/test/8/ low localhost/test/16/ because second callback not called

This is because your map signature for value_low will always match - changing the variable name does not change the signature. You need to use a single route and add logic to it or change the signature.

billybigpotatoes avatar Apr 01 '21 16:04 billybigpotatoes

@billybigpotatoes, Yes are your right, but when i want single route and separate logic its broken.

websharik avatar Apr 05 '21 03:04 websharik