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.