1111
1212namespace Symfony \UX \LiveComponent \Util ;
1313
14+ use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
1415use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
1516use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
16- use Symfony \Component \Routing \RequestContext ;
1717use Symfony \Component \Routing \RouterInterface ;
1818
1919/**
@@ -44,7 +44,7 @@ public function createFromPreviousAndProps(
4444
4545 try {
4646 $ newUrl = $ this ->createPath ($ previousUrl , $ pathMappedProps );
47- } catch (ResourceNotFoundException |MissingMandatoryParametersException ) {
47+ } catch (ResourceNotFoundException |MethodNotAllowedException | MissingMandatoryParametersException ) {
4848 return null ;
4949 }
5050
@@ -60,22 +60,10 @@ public function createFromPreviousAndProps(
6060
6161 private function createPath (string $ previousUrl , array $ props ): string
6262 {
63- // LiveComponent uses POST requests by default but previousUrl might only match a GET route.
64- $ ret = $ this ->router ->getContext ();
65- $ this ->router ->setContext (RequestContext::fromUri ($ previousUrl ));
66- try {
67- $ route = $ this ->router ->match ($ previousUrl );
68- } catch (\Exception $ e ) {
69- return $ previousUrl ;
70- } finally {
71- $ this ->router ->setContext ($ ret );
72- }
73-
74- if (!isset ($ route ['_route ' ]) || '' === $ route ['_route ' ]) {
75- return $ previousUrl ;
76- }
77-
78- return $ this ->router ->generate ($ route ['_route ' ] ?? '' , $ props );
63+ return $ this ->router ->generate (
64+ $ this ->router ->match ($ previousUrl )['_route ' ] ?? '' ,
65+ $ props
66+ );
7967 }
8068
8169 private function replaceQueryString ($ url , array $ props ): string
0 commit comments