Custom Drupal breadcrumbs - how to disable the last item I have a D8 custom module providing its own breadcrumbs.
The breadcrumbs are shown perfectly, but the current page (last item) is shown as a link. I want to change Change this but as I see it, the ::build method requires the $links to be returned as an array of Link.

use ...

class BreadcrumbsBuilder implements BreadcrumbBuilderInterface {

  public function __construct() {
    ...
  }

  public function applies(RouteMatchInterface $route_match) {

    $result = // calculate logic
    return $result;
  }

  public function build(RouteMatchInterface $route_match) {
    $crumbs = new Breadcrumb();
    // prepare the data
    $links = $this-&gt;buildLinks($prepared_data);

    $crumbs-&gt;buildLinks($links);
      return $crumbs;
  }

  private function buildLinks($prepared_data) {
    $links = [
      Link::createFromRoute(t('Home'), '&lt;front&gt;'),
      Link::createFromRoute($title, 'entity.node.canonical', ['node' =&gt; $this-&gt;node-&gt;id()]),
    ];

    foreach($prepared_data as $data) {
      $links[] = Link::fromTextAndUrl($page_title, Url::fromUserInput($dummy_data));
    }
    return $links;
  }

}


The crumbs are shown properly as:

home &gt;&gt; My Title &gt;&gt; page_1 &gt;&gt; page_2


But page_2 is the current page, so it should not show as a link
To answer my own question:
The last link should point to route name '&lt;none&gt;' and that removes the href attribute from the item. So after all super easy.

// untested
foreach($prepared_data as $data) {
  $links[] = $is_last_link($data) 
     ? Link::createFromRoute($page_title, '&lt;none&gt;')
     : Link::fromTextAndUrl($page_title, Url::fromUserInput());
  }


Related:
It appears Drupal 8 core does not provide the current page in the breadcrumbs.
The contributed module Easy Breadcrumbs does this for D7. The D8 version is in still in sandbox.
Reference: Blog post.