File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
src/LiveComponent/src/Util Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 1313
1414use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
1515use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
16+ use Symfony \Component \Routing \RequestContext ;
1617use Symfony \Component \Routing \RouterInterface ;
1718
1819/**
@@ -59,10 +60,22 @@ public function createFromPreviousAndProps(
5960
6061 private function createPath (string $ previousUrl , array $ props ): string
6162 {
62- return $ this ->router ->generate (
63- $ this ->router ->match ($ previousUrl )['_route ' ] ?? '' ,
64- $ props
65- );
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 );
6679 }
6780
6881 private function replaceQueryString ($ url , array $ props ): string
You can’t perform that action at this time.
0 commit comments