Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second route callback dont work in similar routes #28

Open
websharik opened this issue Jan 28, 2021 · 6 comments
Open

Second route callback dont work in similar routes #28

websharik opened this issue Jan 28, 2021 · 6 comments
Labels
needs info Need more info on this issue in order to properly investigate

Comments

@websharik
Copy link

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
Copy link
Author

AltoRouter match return only first found route.

@jarednova
Copy link
Member

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

@jarednova jarednova added the needs info Need more info on this issue in order to properly investigate label Feb 1, 2021
@websharik
Copy link
Author

websharik commented Feb 1, 2021

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
Copy link
Author

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
Copy link

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
Copy link
Author

websharik commented Apr 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info Need more info on this issue in order to properly investigate
Projects
None yet
Development

No branches or pull requests

3 participants