The query string is not part of the route. The controller fetches the query parameters from the webserver request and does the processing, in this case returns a redirect:
$request = \Drupal::request();
$destination = $request->query->get('destination');
return new RedirectResponse($destination);
When generating an url for the example mentioned in the question, the node_type
is a parameter that goes into the route as configured in the routing yml file and the destination is a query parameter that is appended to the url and is not part of the route:
$url = \Drupal\Core\Url::fromRoute(
'node.add',
array('node_type' => $type->id()),
array(
'query' => array('destination' => $destination),
'absolute' => TRUE,
)
);
On both sides the routing system ignores whatever you put in the query of the url, you have to handle this in the code yourself.
adding the destination in the route definition
? Should the custom route be done by code using route callback ? Thanks