How do I pass parameters from a form redirect to a controller? I feel like it should be easier to find this stuff out. I'm trying to pass some data from a form submission to a controller, and do something based on that data. What is the most Drupal way to do this (i.e. without accessing the request object directly)?

The form in a custom module that extends FormBase has this method.

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    $var_to_send = $form_state-&gt;getValue('val_to_get'); 
    $form_state-&gt;setRedirect('my.route', [ 'sent_var' =&gt; $var_to_send ]);
}


In this case, my.route is configured like this.

my.route:
  ...
  defaults:
    _controller: '\Drupal\custom_module\Controller\MyController::index'
    ...


I have the following method in \Drupal\custom_module\Controller\MyController.php.

public function index() {
    $params = \Drupal::request()-&gt;query-&gt;all();
    $this-&gt;myfunc($params['sent_var']);
}


This page says that what I'm doing is highly discouraged. So how should I access URL parameters in a controller?
In a route callback like a controller you can pull the request with a typed function parameter:

use Symfony\Component\HttpFoundation\Request;

  public function index(Request $request) {
    $query_parameters = $request-&gt;query-&gt;all();

  }