How to use 'use-ajax' class with pages created by controller?
This is a render array that create a link that open a modal windows.

use Drupal\Core\Url;

public function build() {
$output = array();
$output['overlay_link'] = array(
  '#type' =&gt; 'link',
  '#title' =&gt; $this-&gt;t('Add an activity'),
  '#url' =&gt; Url::fromRoute('node.add', ['node_type' =&gt; 'event'], ['query' =&gt; ['destination' =&gt; $destination],
    'absolute' =&gt; TRUE,]),
  '#attributes' =&gt; [
    'class' =&gt; ['use-ajax', 'button', 'secondary'],
    'data-dialog-type' =&gt; 'modal',
    'data-dialog-options' =&gt; \Drupal\Component\Serialization\Json::encode(['title' =&gt; t('Add an activity'), 'width' =&gt; 800,]),
  ],
);
 return $output;
}