Routing and path aliases I have created a module with its routing.yml file.

mymodule.dossier:
  path: '/dossiers/{node}/dossier'
  defaults:
    _entity_view: 'node.dossier_dossier'
  requirements:
    _permission: 'access content'


I have created a custom view mode (node.dossier_dossier) and the corresponding Twig template. If I go to dossiers/1/dossier, it works, and it displays the node with the dossier_dossier view mode and appropriate template.

node/1 has /dossiers/my-custom-path as its path alias, which is automatically set from the Pathauto module. If I try to access /dossiers/my-custom-path/dossier, it returns a Page not found error.

How can I make this route work for my nodes for both (default and path aliases) URLs?

Edit: I should maybe mention why I need that:


/dossiers/my-custom-path should display the node using the default view mode
/dossiers/my-custom-path/dossier should display the node using the dossier_dossier view mode
/dossiers/my-custom-path/abstract should display the node using yet another view mode (I'd create another route for that one presumably)
Pathauto can't do this, it can only generate aliases to the default view mode.

You can write your own Pathauto module, which generates for each view mode a separate aliases. For a single purpose module there is not much work to do, you only need to generate the aliases and use

\Drupal::service('path.alias_storage')-&gt;save($source, $alias);


to save them.

The problem is, you get a very large url_alias table.

Or use route_callbacks: in *.routing.yml, then define in this callback for each view mode a different route, which calls a Controller, which then in case you have a hit on the route will look up the middle part of the alias and return a redirect to the node in the requested view mode. This is without the static alias table, but may take longer for each request.