Description
Hello,
Part of the discussion about faceted search/result combo (challenge point 3), I'm playing with live components and the feature to change an url when a LiveProp changes; I was wondering if there is actually a setting to remove the given param when its empty.
I explain a bit:
I have a "name" field wired to a live component with url: true. Assuming I write inside, my url will be http://localhost/index?name=foo
. The question is if I reset the field, the URL will be http://localhost/index?name=
but is there a way to enforce url to something like http://localhost/index
? It's cleaner, yes, but I think it's not trivia if you have a lot of params, because of a faceted search or other: http://localhost/index?name=&locationType=&location=&type=&domain=&status=&startDate=&endDate=
As far as I can think, I see 2 ways to add this:
- Implicitely, by declaring differently both behaviors:
#[LiveProp(writable: true, url: true)]
public string $search = ''; //Because still a string, param stays on URL
#[LiveProp(writable: true, url: true)]
public ?string $brand = null; //Because nullable, param disappears on URL if null
- Explicitely, by adding an explicite "bool $hideEmptyParam" property to the Symfony\UX\LiveComponent\Metadata\UrlMapping class.
I feel like the first is more elegant but that's only brainstorming!
If I may help in any way,
Best regards,