How do I redirect users after they submit a form? How do I redirect users after they submit a form? I tried the following code, but it doesn't work. It says the route doesn't exist.

public  function submitForm(array &amp;$form, FormStateInterface $form_state){
   $url = Url::fromRoute('/mon-profil/obtenir_document'); // == /node/1
   $form_state-&gt;setRedirectUrl($url);
}
You're getting that error because fromRoute() takes the route name as the argument, not a literal path.

Assuming you know the node id you want to redirect to:

$url = Url::fromRoute('entity.node.canonical', array('node' =&gt; $node_id));


You don't ever want to redirect to internal paths like that (in your question) because they are subject to change.