0

When I am defining routes in config/routes.php then those routes are not working in symfony 6.1

use App\Controller\BlogController;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes) {
   $routes->add('blog_list', '/blog/{page}') 
       ->controller([BlogController::class, 'list']) 
       ->defaults(['page' => 1])
       ->requirements(['page' => '\d+']);
};
Cerad
  • 48,157
  • 8
  • 90
  • 92
  • For future reference, use three back ticks to format code blocks. – Cerad Oct 04 '22 at 14:41
  • Make sure you don't have a config/routes.yaml file still hanging around. It's kind of silly but you can have routes.yaml or routes.php but not both. MicroKernelTrait::configureRoutes() shows the loading process. And use `bin/console debug:router` to verify your routes. – Cerad Oct 04 '22 at 14:47
  • Thanks, after removing routes.yaml it is working. Is there anyway to keep it both? – Prakash Oct 04 '22 at 15:19
  • You can copy the configureRoutes method from the MicroKernalTrait to your src/Kernel class and tweak to your heart's content. – Cerad Oct 04 '22 at 15:43

0 Answers0