Skip to main content
3 of 4
added 320 characters in body
MrUpsidown
  • 598
  • 1
  • 7
  • 23

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
MrUpsidown
  • 598
  • 1
  • 7
  • 23