3

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.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Barskey
  • 423
  • 2
  • 5
  • 18

2 Answers2

10

you have to name the route, like:

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

and then:

return $this->redirectToRoute('homepage');
Nobady
  • 1,074
  • 2
  • 11
  • 35
1

You can try this way:

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


return $this->redirect('/');
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42
  • Since I'm using xampp this redirects to xampp's dashboard but I'm sure it would work on symfony's server, thanks. – Barskey Jan 23 '20 at 13:52