Home > front end >  Unable to generate a URL for the named route "main" as such route does not exist
Unable to generate a URL for the named route "main" as such route does not exist

Time:06-24

I'm learning Symfony 6.0.9 and I'm trying to build an eshop website and I have a problem : I created the UserAuthenticator.php file and I did all the changes to create new users in my database. But when I try to register or log in, this mesage appears :

Unable to generate a URL for the named route "main" as such route does not exist.

I tried to to a symfony console debug:router and this is what I got :

  Name                       Method   Scheme   Host   Path
 -------------------------- -------- -------- ------ ----------------------------------- 
  _preview_error             ANY      ANY      ANY    /_error/{code}.{_format}
  _wdt                       ANY      ANY      ANY    /_wdt/{token}
  _profiler_home             ANY      ANY      ANY    /_profiler/
  _profiler_search           ANY      ANY      ANY    /_profiler/search
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open
  _profiler                  ANY      ANY      ANY    /_profiler/{token}
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css
  app_main                   ANY      ANY      ANY    /main
  app_register               ANY      ANY      ANY    /register
  app_login                  ANY      ANY      ANY    /login
  app_logout                 ANY      ANY      ANY    /logout
 -------------------------- -------- -------- ------ -----------------------------------

Here is my MainController.php :


namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class MainController extends AbstractController
{
    #[Route('/main', name: 'app_main')]
    public function index(): Response
    {
        return $this->render('main/index.html.twig');
    }
}

I tried to remove the "main" to leave the "/", but it doesn't work.

Can you please help me ? If you need other screnshots, tell me. Thank you.

CodePudding user response:

Somewhere in your application you using main route instead of app_main route. Just look for it in your project and replace it to make it work!

CodePudding user response:

Ok, the problem is solved. I changed the name of the route in the main controller and it perfectly works now, thanks for your answers ^^

  • Related