Search code examples
phpsymfonysymfony4symfony-4.4

Redirect to "/" route in symfony


I'm trying to redirect to the "/" route (same page) after a form submission:

/**
 * @Route("/")
 */

My approach:

return $this->redirectToRoute('/');

Gives me the following error:

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


Solution

  • you have to name the route, like:

    /**
    * @Route("/", name="homepage")
    */
    

    and then:

    return $this->redirectToRoute('homepage');