11
11
12
12
namespace Symfony \UX \LiveComponent \Util ;
13
13
14
+ use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
14
15
use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
15
16
use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
16
- use Symfony \Component \Routing \RequestContext ;
17
17
use Symfony \Component \Routing \RouterInterface ;
18
18
19
19
/**
@@ -44,7 +44,7 @@ public function createFromPreviousAndProps(
44
44
45
45
try {
46
46
$ newUrl = $ this ->createPath ($ previousUrl , $ pathMappedProps );
47
- } catch (ResourceNotFoundException |MissingMandatoryParametersException ) {
47
+ } catch (ResourceNotFoundException |MethodNotAllowedException | MissingMandatoryParametersException ) {
48
48
return null ;
49
49
}
50
50
@@ -60,22 +60,10 @@ public function createFromPreviousAndProps(
60
60
61
61
private function createPath (string $ previousUrl , array $ props ): string
62
62
{
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
+ );
79
67
}
80
68
81
69
private function replaceQueryString ($ url , array $ props ): string
0 commit comments