How do I get parameters from form redirect? I've made a form and I'm trying to get the submit result into a redirect page with URL api:

 public function submitForm(array &amp;$form, FormStateInterface $form_state)
    {

    $metier=$form_state-&gt;getValue('metier');
    $position=$form_state-&gt;getValue('position');

    //$form_state-&gt;setRedirect('recherche.resultat',array('param'=&gt;'test');

    $url = new Url('recherche.resultat');
    $url-&gt;setOptions(array('param'=&gt;'test2'));
    $url-&gt;setRouteParameters(array('param'=&gt;'test2'));

    $form_state-&gt;setRedirectUrl($url);

    drupal_set_message("envoyer");

}


I set two options :

$url-&gt;setOptions(array('param'=&gt;'test2'));


and 

$url-&gt;setRouteParameters(array('param'=&gt;'test2'));


The form redirect me and this is my controller :

public function resultat()
{
    $request = \Drupal::request();
    $url = Url::createFromRequest($request);
    kint($url);
    kint($url-&gt;getOptions());
    kint($url-&gt;getRouteParameters());
    return array('#markup'=&gt;t('test'));

}


The two methods :

    kint($url-&gt;getOptions());
    kint($url-&gt;getRouteParameters());


are empty

This is my routing :

 recherche.resultat:
  path: '/resultat'
  defaults:
    _title: 'resultat'
    _controller: '\Drupal\recherche\Controller\ResultatRechercheController::resultat'
  requirements:
     _permission: 'access content'


The parameters are in the URL and I can get them with $_GET but how can I get with the URL API?
Ok i got it by this way :

So i have 2 parameters from my form to pass to my controller :

public function submitForm(array &amp;$form, FormStateInterface $form_state)
{

    $metier=$form_state-&gt;getValue('metier');
    $position=$form_state-&gt;getValue('position');

    $url = \Drupal\Core\Url::fromRoute('recherche.resultat')
          -&gt;setRouteParameters(array('metier'=&gt;$metier,'position'=&gt;$position));

    $form_state-&gt;setRedirectUrl($url);


}


The key is in the YAML routing, you need to build your path like that for get parameters ( name of parameters need to be same as your route, see previous function (submitForm)) :

recherche.resultat:
  path: '/resultat/{metier}/{position}'
  defaults:
    _title: 'resultat'
    _controller: '\Drupal\recherche\Controller\ResultatRechercheController::resultat'
    metier: ''
    position: ''
  requirements:
     _permission: 'access content'


And in my controller for get my parameters :

Class: ResultatRechercheController

 public function resultat($metier, $position)
    {

        kint($metier);
        kint($position);

        return array('#markup'=&gt;t('la premiere spécialite est @specialite',array('@specialite'=&gt;'test')));

    }


And the URL is clean : 


  localhost:8888//monsite.com/resultat/{metier}/{position}