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 13
13
14
14
use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
15
15
use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
16
+ use Symfony \Component \Routing \RequestContext ;
16
17
use Symfony \Component \Routing \RouterInterface ;
17
18
18
19
/**
@@ -59,10 +60,22 @@ public function createFromPreviousAndProps(
59
60
60
61
private function createPath (string $ previousUrl , array $ props ): string
61
62
{
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 );
66
79
}
67
80
68
81
private function replaceQueryString ($ url , array $ props ): string
You can’t perform that action at this time.
0 commit comments