Fast Route Bad Route Exception

I am getting the following error

Static route “/pacientes/nuevoNumero” is shadowed by previously defined variable route “/pacientes/([^/]+)” for method "GET

when I trying to get the following routes
api/usuarios/1 and api/pacientes/1

#Users routes
$app->get('/usuarios/', 'UserController:GetAll')->add('LoginMiddleware');
$app->get('/usuarios/{id}', 'UserController:GetById')->add('LoginMiddleware');
$app->post('/usuarios/', 'UserController:Add')->add('LoginMiddleware');
$app->post('/usuarios/login', 'UserController:Login')->add('LoginMiddleware');
$app->put('/usuarios/{id}', 'UserController:Edit')->add('LoginMiddleware');
$app->delete('/usuarios/{id}', 'UserController:Remove')->add('LoginMiddleware');

#Patients routes
$app->get('/pacientes/{id}', 'PatientController:GetById')->add('LoginMiddleware');
$app->get('/pacientes/', 'PatientController:GetAll')->add('LoginMiddleware');
$app->get('/pacientes/nuevoNumero', 'PatientController:NewNumber')->add('LoginMiddleware');
$app->post('/pacientes/porNombre', 'PatientController:GetByName')->add('LoginMiddleware');
$app->post('/pacientes/porNumero', 'PatientController:GetByNumber')->add('LoginMiddleware');
$app->post('/pacientes/porDocumento', 'PatientController:GetByDocument')->add('LoginMiddleware');

could anyone help me to find the issue?
thanks!

Try reordering your routes like below.

$app->get('/pacientes/nuevoNumero', 'PatientController:NewNumber')->add('LoginMiddleware');
$app->get('/pacientes/{id}', 'PatientController:GetById')->add('LoginMiddleware');
$app->get('/pacientes/', 'PatientController:GetAll')->add('LoginMiddleware');
2 Likes

Hi @silentworks that was the solution, but why with that order now works?

@mlazzeri the router execute the callback of the very first valid path.

So: ‘/pacientes/{id}’ matched before of: ‘/pacientes/nuevoNumero’

2 Likes

thanks @damianopetrungaro