diff --git a/routing/external_resources.rst b/routing/external_resources.rst index a242ff5d971..1c996e75926 100644 --- a/routing/external_resources.rst +++ b/routing/external_resources.rst @@ -147,6 +147,53 @@ suppose you want to prefix all application routes with ``/site`` (e.g. The path of each route being loaded from the new routing resource will now be prefixed with the string ``/site``. +.. note:: + + If any of the prefixed routes defines an empty path, Symfony adds a trailing + slash to it. In the previous example, an empty path prefixed with ``/site`` + will result in the ``/site/`` URL. If you want to avoid this behavior, set + the ``trailing_slash_on_root`` option to ``false``: + + .. configuration-block:: + + .. code-block:: yaml + + # config/routes.yaml + controllers: + resource: '../src/Controller/' + type: annotation + prefix: /site + trailing_slash_on_root: false + + .. code-block:: xml + + + + + + + + + .. code-block:: php + + // config/routes.php + use Symfony\Component\Routing\RouteCollection; + + $app = $loader->import('../src/Controller/', 'annotation'); + // the second argument is the $trailingSlashOnRoot option + $app->addPrefix('/site', false); + // ... + + .. versionadded:: 4.1 + The ``trailing_slash_on_root`` option was introduced in Symfony 4.1. + Prefixing the Names of Imported Routes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~