Upstatement / routes

Simple routing for WordPress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Second route callback dont work in similar routes

websharik opened this issue · 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.

AltoRouter match return only first found route.

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

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

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

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, Yes are your right, but when i want single route and separate logic its broken.