From 96763bf74a60dfc1de24b4de9f8756567a1ebde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Thu, 8 Jan 2026 23:35:19 +0100 Subject: [PATCH 1/2] docs: emphasize route exposure requirement before generating URIs --- Resources/doc/usage.rst | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Resources/doc/usage.rst b/Resources/doc/usage.rst index cb04cc9..f7c449b 100644 --- a/Resources/doc/usage.rst +++ b/Resources/doc/usage.rst @@ -76,6 +76,62 @@ Then within your JavaScript development you can use: Routing.setRoutingData(routes); Routing.generate('rep_log_list'); +Exposing Routes +--------------- + +.. important:: + + Before generating URIs for routes in JavaScript, you must expose the routes. Routes are not automatically available in the frontend; they need to be explicitly marked for exposure using one of the methods below. Without exposing routes, the ``Routing.generate()`` method will not work. + +There are several ways to expose routes: + +**1. Using Route Options:** + + Add ``options: ['expose' => true]`` to your route definition. + + **With attributes:** + + .. code-block:: php + + #[Route(path: '/foo/{id}/bar', name: 'my_route', options: ['expose' => true])] + + **With YAML:** + + .. code-block:: yaml + + my_route: + path: /foo/{id}/bar + options: + expose: true + +**2. Configuration in config.yml:** + + Configure a list of routes to expose: + + .. code-block:: yaml + + fos_js_routing: + routes_to_expose: [route_1, route_2] + + You can use regular expressions to match multiple routes: + + .. code-block:: yaml + + fos_js_routing: + routes_to_expose: ['^api_.*'] + +**3. Preventing Exposure:** + + To explicitly prevent a route from being exposed, set ``expose: false``: + + .. code-block:: yaml + + my_secret_route: + path: /admin + options: + expose: false + +For internationalized routes (e.g., with JMSI18nRoutingBundle), ensure the exposed routes match the locale-prefixed names or use patterns. Generating URIs --------------- From bfd4536cfe39aa88928d813ff148ceb18b25db13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Thu, 8 Jan 2026 23:44:07 +0100 Subject: [PATCH 2/2] docs: add API Platform route exposure documentation. Closes #380 --- Resources/doc/usage.rst | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Resources/doc/usage.rst b/Resources/doc/usage.rst index f7c449b..06dbb6a 100644 --- a/Resources/doc/usage.rst +++ b/Resources/doc/usage.rst @@ -133,6 +133,42 @@ There are several ways to expose routes: For internationalized routes (e.g., with JMSI18nRoutingBundle), ensure the exposed routes match the locale-prefixed names or use patterns. +**4. Exposing Routes in API Platform:** + + If you are using `API Platform`_, you can expose routes using the configuration method with regular expressions, or by setting options on specific operations. + + **Using Configuration:** + + .. code-block:: yaml + + fos_js_routing: + routes_to_expose: ['api_.*'] + + This will expose all routes starting with 'api_'. You can use more specific patterns like ``['api_jobs_.*', 'api_types_.*']``. + + **Using Operation Options:** + + For specific operations, add ``'expose' => true`` to the options: + + .. code-block:: php + + #[ApiResource( + operations: [ + new GetCollection( + options: ['expose' => true] + ) + ] + )] + class MyEntity {} + + To find the exact route names generated by API Platform, use the command: + + .. code-block:: bash + + bin/console debug:router + +.. _`API Platform`: https://api-platform.com/ + Generating URIs ---------------