How to get term by path or alias?
I usually do something like this:

&lt;?php

use Drupal\taxonomy\Entity\Term;

function hook_preprocess_page(&amp;$vars) {
  $route = \Drupal::routeMatch();
  if ($route-&gt;getRouteName() == 'entity.taxonomy_term.canonical') {
    $term_id = $route-&gt;getRawParameter('taxonomy_term');
    $term = Term::load($term_id);
  }
}