How deal with taxonomy term parameter in multilingue site? I have a custom controller, who take the tid parameter :

/myroute/{tid}


The tid is upcast with the taxonomy Term so in my controller method I have:

public function index(TaxonomyTerm $tid)


In this function I can get the taxonomy entity.

But for call my controller, it's not SEO friendly... i have : /myroute/43 for example.

So I won't pass the term name, because you can have spécial caractere and it's not a good pratice in a multilingue site.

So for me the best way is to work with pathauto, generate the path for the taxonomy term so i can have :

/[term_category]/[term_name]

Now my question is how pass this to my controller.

I need to call my controller like that:

&lt;a href="myroute/{param_taxo}"&gt;

So I am not sure how get the tid of the term with friendly url for SEO.

Any experience about that?
You must edit your route to be like this, /myroute/{alias}.

Then you can load the term in your controller like this:

public function index($alias) {
  // Find the term by path alias.
  $path = \Drupal::service('path_alias.manager')-&gt;getPathByAlias($alias);
  if (preg_match('/taxonomy\/term\/(\d+)/', $path, $matches)) {
    $term = $this-&gt;entityTypeManager-&gt;getStorage('taxonomy_term')-&gt;load($matches[1]);
  }
  if (isset($term) &amp;&amp; $term instanceof TermInterface) {
    $term_id = $term-&gt;id();
  }
}


NB: The path_alias.manager service is added in Drupal 8.8.x, if you use an older version you must use the path.alias_manager service instead.