Routing custom module with alphabetic pagination My custom module:
- Plugin/Ziektes.php array returns to hook_theme

public function build() {

$letter_path = 'B';
$path = base_path();
$current_url = Url::fromRoute('&lt;current&gt;');
$current_path = $current_url-&gt;toString();

// Query for newest articles and return max 3 results.
$query = \Drupal::entityQuery('node');
$news = $query-&gt;condition('type', 'ziekte')
  -&gt;condition('status', 1)
  -&gt;condition('title', $letter_path, 'STARTS_WITH' )
  -&gt;sort('created', 'ASC')
  -&gt;execute();

// LoadMultiple News in $nodes variable
$nodes = Node::loadMultiple($news);

// Return $nodes variable with name items to the module.
return array(
  '#theme' =&gt; 'mytheme_ziektes',
  '#items' =&gt; $nodes,
  '#path'  =&gt; $path,
  '#url'   =&gt; $current_path,
);


I have an alphabetical pagination printedn in twig like this:


Below this pagination there are the results of nodes for example in the letter 'B' there are nodes from content-type 'ziektes' that starts with the letter B.

As you can see in my module Ziektes.php file its not dynamic it uses 

$letter_path = 'B';
-&gt;condition('title', $letter_path, 'STARTS_WITH' ).

When there is clicked on a letter it goes to ziektes/'theletter' for example ziektes/b so that I can get the letter from the url and make the query dynamic.

But at page ziekte/*anyletter I get an 404 page not found so I've made a Controller and a routing:

Routing:

myroutingname.settings:
  path: '/ziektes/{letter}'
  defaults:
    _controller: '\Drupal\myblocksroute\Controller\ZiektesController::ziekte'
    _title: 'Routing Ziektes'
  requirements:
    _permission: 'access my routing ziektes'


Controller:

namespace Drupal\myblocksroute\Controller;

class ZiektesController
{
  public function ziekte($letter) {
    return [
      '#title' =&gt; $letter
    ];
  }
}


This returns the letter that is clicked, that's good! But Its only a new page with the as title the letter 'b' for example, I can't keep the twig template and the EntityQuery are not reachable from here. It suppose to stay at /ziektes form template but the url is /ziektes/b, so that the query will check the letter after the ziektes/ where I can make my $letter_path dynamic.

How can I do this?
As I alluded to in my comment, you are close, I believe. Here are some changes to get you in the right direction which begins by extending ControllerBase:

class ZiektesController extends ControllerBase
{

  // set any scope/variables here

  public function __construct($args...) {
    // set your injected dependencies to local variables
  }

  public static function create($args...) {
    // here you inject dependencies you need
  }

  public function ziekte($letter) {    
    return array(
     '#theme' =&gt; 'mytheme_ziektes',
     '#items' =&gt; $this-&gt;queryNodes($letter),
     '#path'  =&gt; $path,
     '#url'   =&gt; $current_path,
    );
  }

  protected function queryNodes($letter) {
    // the following code can be refactored
    $letter_path = 'B';
    $path = base_path();
    $current_url = Url::fromRoute('&lt;current&gt;');
    $current_path = $current_url-&gt;toString();

    // Query for newest articles and return max 3 results.
    $query = \Drupal::entityQuery('node');
    $nodes = $query-&gt;condition('type', 'ziekte')
      -&gt;condition('status', 1)
      -&gt;condition('title', $letter_path, 'STARTS_WITH' )
      -&gt;sort('created', 'ASC')
      -&gt;execute();

    return count($nodes) ? $this-&gt;entityTypeManager-&gt;getStorage('node')-&gt;loadMultiple($nids) : array();
  }
}


ControllerBase should inject everything you need already, like entityTypeManager. That can be used to load nodes, as shown above. You don't need to call Node, and you likely don't have to do the same for Url either.

You can bring in your query as a helper method and you can inject entityQuery into your controller, see this comment on how to do that. That way, you're not using the global static container (\Drupal::). Then your code becomes:

    // Query for newest articles and return max 3 results.
    $query = $this-&gt;entityQuery-&gt;get('node');
    $nodes = $query-&gt;condition('type', 'ziekte')
      -&gt;condition('status', 1)
      -&gt;condition('title', $letter_path, 'STARTS_WITH' )
      -&gt;sort('created', 'ASC')
      -&gt;execute();


I am not sure why you need path and url though - every filter link will be routed to '/ziektes/{letter}'.