How to redirect to content if view have 1 result?
In your theme's themename.theme file add:

At the very top add:

use Drupal\views\ViewExecutable;
use Symfony\Component\HttpFoundation\RedirectResponse;


Then add:

/*
 * Implements hook_views_pre_render()
 */
function THEMENAME_views_pre_render(ViewExecutable $view) {
    if($view-&gt;id() == "view_name" &amp;&amp; $view-&gt;current_display == 'view_machine_name') {
      if (!empty($view-&gt;result) &amp;&amp; count($view-&gt;result) == 1) {
        $url = $view-&gt;result[0]-&gt;_entity-&gt;toUrl()-&gt;toString();
        $response = new RedirectResponse($url);
        $response-&gt;send();
      }
    }
}


Clear the cache so changes kick in. 





my_module/src/Controller/ViewPageController.php

namespace Drupal\my_module\Controller;

use Drupal\Core\Cache\CacheableRedirectResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\views\Views;

/**
 * Defines HelloController class.
 */
class ViewPageController extends ControllerBase {

  public function content() {

    $view = Views::getView('view_name');
    $view-&gt;setDisplay('view_machine_name');
    $view-&gt;execute();

    if (!empty($view-&gt;result) &amp;&amp; count($view-&gt;result) == 1) {

      $url = $view-&gt;result[0]-&gt;_entity-&gt;toUrl()-&gt;toString(TRUE);
      $response = new CacheableRedirectResponse($url-&gt;getGeneratedUrl());
      $response-&gt;getCacheableMetadata()-&gt;addCacheTags($view-&gt;getCacheTags());
      $response-&gt;addCacheableDependency($url);
      return $response;

    }
    else {

      return [
        '#type' =&gt; 'view',
        '#name' =&gt; 'view_name',
        '#view' =&gt; $view,
        '#display_id' =&gt; 'view_machine_name',
        '#embed' =&gt; TRUE,
        '#cache' =&gt; $view-&gt;getCacheTags(),
      ];

    }

  }

}


This is the view_machine_name.