Upstatement / routes

Simple routing for WordPress
188 stars 39 forks source link

Second route callback dont work in similar routes #28

Open websharik opened 3 years ago

websharik commented 3 years ago

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 commented 3 years ago

AltoRouter match return only first found route.

jarednova commented 3 years ago

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

websharik commented 3 years ago

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 commented 3 years ago
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

billybigpotatoes commented 3 years ago
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.

websharik commented 3 years ago

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