Redirect to another route with variables

Hello everyone,

Currently i have 2 routes on my app

  • homepage : /
  • results : /results

I have a form on my homepage, the action of the form is my result route.
When i fire error in my result route, i want redirect to my homepage with error variable.

I’m trying to do this on my controller, but the redirection works fine but on my twig view, when i dump my error, i have nothing.

	try {
		$results = $app_manager->getResults($datas);
	} catch (\Exception $e) {
		$routeContext = RouteContext::fromRequest($request);

		$path = $routeContext->getRouteParser()->urlFor('homepage',  [
			'error' => $e->getMessage(),
			'form_values' => $datas
		]);

		return $response->withHeader('Location', $path)->withStatus(302);
	}

If anyone has an explanation, that would be great.
Thanks a lot.

Camille