How to get term by path or alias? I've seen this question posted many places, but no answers - or relevant answer. i.e. how to get term object or ID from path or alias e.g. /cat/subcat or /taxonomy/term/6??
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);
  }
}