Drupal 8

Drupal Get Taxonomy Term From Route

The process of loading taxonomy term from routematch for Drupal 8, 9 and 10 is as follows.

$tax = \Drupal::routeMatch()->getParameter('taxonomy_term');
if ($tax instanceof \Drupal\taxonomy\TermInterface) {
 // $tax
}

We got the taxonomy from the route with the following code.

$tax = \Drupal::routeMatch()->getParameter('taxonomy_term');

With the code below, we confirmed that the entity we loaded is a taxonomy.

Drupal Get Node From Route

For Drupal 8 / 9 and 10, finding the node from the route is done with the following code.

$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
 // $node 
}