@@ -67,19 +67,23 @@ private function getLivePropsToMap(Request $request): array
6767 $ liveData = $ request ->attributes ->get ('_live_request_data ' ) ?? [];
6868 $ values = array_merge ($ liveData ['props ' ] ?? [], $ liveData ['updated ' ] ?? []);
6969
70- $ urlLiveProps = [];
70+ $ urlLiveProps = [
71+ 'path ' => [],
72+ 'query ' => [],
73+ ];
7174 foreach ($ metadata ->getAllLivePropsMetadata ($ component ) as $ liveProp ) {
7275 $ name = $ liveProp ->getName ();
7376 $ urlMapping = $ liveProp ->urlMapping ();
7477 if (isset ($ values [$ name ]) && $ urlMapping ) {
75- $ urlLiveProps [$ urlMapping ->as ?? $ name ] = $ values [$ name ];
78+ $ urlLiveProps [$ urlMapping ->mapPath ? 'path ' : 'query ' ][$ urlMapping ->as ?? $ name ] =
79+ $ values [$ name ];
7680 }
7781 }
7882
7983 return $ urlLiveProps ;
8084 }
8185
82- private function computeNewUrl (string $ previousUrl , array $ newProps ): string
86+ private function computeNewUrl (string $ previousUrl , array $ livePropsToMap ): string
8387 {
8488 $ parsed = parse_url ($ previousUrl );
8589
@@ -89,10 +93,16 @@ private function computeNewUrl(string $previousUrl, array $newProps): string
8993 }
9094 parse_str ($ parsed ['query ' ] ?? '' , $ previousQueryParams );
9195
92- return $ this ->router ->generate (
96+ $ newUrl = $ this ->router ->generate (
9397 $ this ->router ->match ($ url )['_route ' ],
94- array_merge ($ previousQueryParams , $ newProps )
98+ array_merge ($ previousQueryParams , $ livePropsToMap [ ' path ' ] )
9599 );
100+ parse_str (parse_url ($ newUrl )['query ' ] ?? '' , $ queryParams );
101+ $ queryString = http_build_query (array_merge ($ queryParams , $ livePropsToMap ['query ' ]));
102+
103+ return preg_replace ('/[?#].*/ ' , '' , $ newUrl ).
104+ ('' !== $ queryString ? '? ' : '' ).
105+ $ queryString ;
96106 }
97107
98108 /**
0 commit comments