@@ -1612,6 +1612,59 @@ and its URL will be ``/blog/{_locale}``. The route of the ``show()`` action will
1612
1612
will also validate that the ``_locale `` parameter matches the regular expression
1613
1613
defined in the class annotation.
1614
1614
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
+
1615
1668
.. seealso ::
1616
1669
1617
1670
Symfony can :doc: `import routes from different sources </routing/custom_route_loader >`
0 commit comments