8000 minor #15768 [Routing] Readd the explanation of trailing_slash_on_roo… · symfony/symfony-docs@ef6e6ba · GitHub
[go: up one dir, main page]

Skip to content

Commit ef6e6ba

Browse files
committed
minor #15768 [Routing] Readd the explanation of trailing_slash_on_root option (javiereguiluz)
This PR was squashed before being merged into the 5.3 branch. Discussion ---------- [Routing] Readd the explanation of trailing_slash_on_root option This was available in older versions ... but somehow was lost during a content reorganization. Let's readd it. Commits ------- ac8eb7d [Routing] Readd the explanation of trailing_slash_on_root option
2 parents eaec8f0 + ac8eb7d commit ef6e6ba

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

routing.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,59 @@ and its URL will be ``/blog/{_locale}``. The route of the ``show()`` action will
16121612
will also validate that the ``_locale`` parameter matches the regular expression
16131613
defined in the class annotation.
16141614

1615+
.. note::
1616+
1617+
If any of the prefixed routes defines an empty path, Symfony adds a trailing
1618+
slash to it. In the previous example, an empty path prefixed with ``/blog``
1619+
will result in the ``/blog/`` URL. If you want to avoid this behavior, set
1620+
the ``trailing_slash_on_root`` option to ``false`` (this option is not
1621+
available when using PHP attributes or annotations):
1622+
1623+
.. configuration-block::
1624+
1625+
.. code-block:: yaml
1626+
1627+
# config/routes/annotations.yaml
1628+
controllers:
1629+
resource: '../../src/Controller/'
1630+
type: annotation
1631+
prefix: '/blog'
1632+
trailing_slash_on_root: false
1633+
# ...
1634+
1635+
.. code-block:: xml
1636+
1637+
<!-- config/routes/annotations.xml -->
1638+
<?xml version="1.0" encoding="UTF-8" ?>
1639+
<routes xmlns="http://symfony.com/schema/routing"
1640+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1641+
xsi:schemaLocation="http://symfony.com/schema/routing
1642+
https://symfony.com/schema/routing/routing-1.0.xsd">
1643+
1644+
<import resource="../../src/Controller/"
1645+
type="annotation"
1646+
prefix="/blog"
1647+
name-prefix="blog_"
1648+
trailing-slash-on-root="false"
1649+
exclude="../../src/Controller/{DebugEmailController}.php">
1650+
<!-- ... -->
1651+
</import>
1652+
</routes>
1653+
1654+
.. code-block:: php
1655+
1656+
// config/routes/annotations.php
1657+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1658+
1659+
return function (RoutingConfigurator $routes) {
1660+
$routes->import('../../src/Controller/', 'annotation')
1661+
// the second argument is the $trailingSlashOnRoot option
1662+
->prefix('/blog', false)
1663+
1664+
// ...
1665+
;
1666+
};
1667+
16151668
.. seealso::
16161669

16171670
Symfony can :doc:`import routes from different sources </routing/custom_route_loader>`

0 commit comments

Comments
 (0)
0