Skip to content

Commit 051b6ef

Browse files
committed
doc
1 parent be343d5 commit 051b6ef

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,46 @@ It can be used to perform more generic operations inside of the modifier that ca
27372737

27382738
The ``query`` value will appear in the URL like ``/search?query=my+important+query&secondary-query=my+secondary+query``.
27392739

2740+
Map the parameter to path instead of query
2741+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2742+
2743+
.. versionadded:: 2.29
2744+
2745+
The ``mapPath`` option was added in LiveComponents 2.29.
2746+
2747+
Instead of setting the ``LiveProp`` as a query parameter, it can be set as route parameter
2748+
by passing the ``mapPath`` option to the ``UrlMapping`` defined for the ``LiveProp``::
2749+
2750+
// ...
2751+
use Symfony\UX\LiveComponent\Metadata\UrlMapping;
2752+
2753+
#[AsLiveComponent]
2754+
class SearchModule
2755+
{
2756+
#[LiveProp(writable: true, url: new UrlMapping(mapPath: true))]
2757+
public string $query = '';
2758+
2759+
// ...
2760+
}
2761+
2762+
2763+
If the current route is defined like this::
2764+
2765+
// src/Controller/SearchController.php
2766+
// ...
2767+
2768+
#[Route('/search/{query}')]
2769+
public function __invoke(string $query): Response
2770+
{
2771+
// ...
2772+
}
2773+
2774+
Then the ``query`` value will appear in the URL like ``https://my.domain/search/my+query+string``.
2775+
2776+
If the route parameter name is different from the LiveProp name, the ``as`` option can be used to map the ``LiveProp``.
2777+
2778+
If the route parameter is not defined, the ``mapPath`` option will be ignored and the LiveProp value will fallback to a query parameter.
2779+
27402780
Validating the Query Parameter Values
27412781
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27422782

0 commit comments

Comments
 (0)