@@ -254,36 +254,21 @@ fn build_path_with_base(to: &str) -> String {
254254}
255255
256256fn get_query_params ( ) -> HashMap < String , String > {
257- #[ wasm_bindgen( inline_js = r#"
258- export function params() {
259- let entries = (new URL(document.URL)).searchParams.entries()
260- let list = []
261- for (const [key, value] of entries) {
262- list.push({key, value})
263- }
264- return list
265- }
266- "# ) ]
267- extern "C" {
268- fn params ( ) -> js_sys:: Array ;
269- }
270-
271- #[ wasm_bindgen]
272- extern "C" {
273- #[ derive( Debug ) ]
274- type Param ;
275-
276- #[ wasm_bindgen( getter, method) ]
277- fn key ( this : & Param ) -> String ;
278-
279- #[ wasm_bindgen( getter, method) ]
280- fn value ( this : & Param ) -> String ;
281- }
257+ let url = web_sys:: Url :: new ( & yew:: utils:: document ( ) . url ( ) . unwrap ( ) ) . unwrap ( ) ;
258+
259+ let iter = js_sys:: try_iter ( & JsValue :: from ( & url. search_params ( ) ) )
260+ . expect ( "try_iter failed" )
261+ . expect ( "try_iter failed" )
262+ . into_iter ( )
263+ . map ( |it| it. unwrap ( ) . unchecked_into :: < js_sys:: Array > ( ) . to_vec ( ) )
264+ . map ( |it| {
265+ let mut iter = it. into_iter ( ) ;
266+ // unwraps are unreachable
267+ // there will be at least 2 values here
268+ // both of them will be strings
269+ ( iter. next ( ) . unwrap ( ) . as_string ( ) . unwrap ( ) , iter. next ( ) . unwrap ( ) . as_string ( ) . unwrap ( ) )
270+ } ) ;
282271
283- let iter = params ( ) . to_vec ( ) . into_iter ( ) . map ( |value : JsValue | {
284- let param = value. unchecked_into :: < Param > ( ) ;
285- ( param. key ( ) , param. value ( ) )
286- } ) ;
287272 let mut map = HashMap :: new ( ) ;
288273
289274 for ( k, v) in iter {
0 commit comments