Skip to content

Commit b73fda4

Browse files
committed
minor #9490 Documented the trailing_slash_on_root option (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #9490). Discussion ---------- Documented the trailing_slash_on_root option This fixes #9484. @nicolas-grekas could you please verify if the config of the example is correct? I don't know if `trailing_slash_on_root` is defined for annotations. Thanks! Commits ------- b4b4954 Documented the trailing_slash_on_root option
2 parents e6100db + b4b4954 commit b73fda4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

routing/external_resources.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,53 @@ suppose you want to prefix all application routes with ``/site`` (e.g.
147147
The path of each route being loaded from the new routing resource will now
148148
be prefixed with the string ``/site``.
149149

150+
.. note::
151+
152+
If any of the prefixed routes defines an empty path, Symfony adds a trailing
153+
slash to it. In the previous example, an empty path prefixed with ``/site``
154+
will result in the ``/site/`` URL. If you want to avoid this behavior, set
155+
the ``trailing_slash_on_root`` option to ``false``:
156+
157+
.. configuration-block::
158+
159+
.. code-block:: yaml
160+
161+
# config/routes.yaml
162+
controllers:
163+
resource: '../src/Controller/'
164+
type: annotation
165+
prefix: /site
166+
trailing_slash_on_root: false
167+
168+
.. code-block:: xml
169+
170+
<!-- config/routes.xml -->
171+
<?xml version="1.0" encoding="UTF-8" ?>
172+
<routes xmlns="http://symfony.com/schema/routing"
173+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
174+
xsi:schemaLocation="http://symfony.com/schema/routing
175+
http://symfony.com/schema/routing/routing-1.0.xsd">
176+
177+
<import
178+
resource="../src/Controller/"
179+
type="annotation"
180+
prefix="/site"
181+
trailing-slash-on-root="false" />
182+
</routes>
183+
184+
.. code-block:: php
185+
186+
// config/routes.php
187+
use Symfony\Component\Routing\RouteCollection;
188+
189+
$app = $loader->import('../src/Controller/', 'annotation');
190+
// the second argument is the $trailingSlashOnRoot option
191+
$app->addPrefix('/site', false);
192+
// ...
193+
194+
.. versionadded:: 4.1
195+
The ``trailing_slash_on_root`` option was introduced in Symfony 4.1.
196+
150197
Prefixing the Names of Imported Routes
151198
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152199

0 commit comments

Comments
 (0)