fix: keep browser history intact when navigating between cards view and participant form

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent bb20176c76
commit f3ea6734a1
7 changed files with 136 additions and 70 deletions
+10 -2
View File
@@ -121,10 +121,11 @@ trait HxTrait
* @param string $templateName The name of the Twig template
* @param string[] $blockNames An array of block names to render
* @param array<string, mixed> $context The context to pass to the template
* @param string|null $pushUrl Optional URL to push to browser history
*
* @return Response Response containing all rendered blocks with OOB context
*/
protected function htmxOobResponse(string $templateName, array $blockNames, array $context = []): Response
protected function htmxOobResponse(string $templateName, array $blockNames, array $context = [], ?string $pushUrl = null): Response
{
$html = '';
// Add a flag to the context so templates can conditionally add the hx-swap-oob attribute.
@@ -135,6 +136,13 @@ trait HxTrait
$html .= $this->renderBlockView($templateName, $blockName, $oobContext);
}
return new Response($html);
$response = new Response($html);
// Set HX-Push-Url header if URL is provided
if (null !== $pushUrl) {
$response->headers->set('HX-Push-Url', $pushUrl);
}
return $response;
}
}