Explorar el Código

Fix client side liveview links (#3341)

* Fix liveview links

* Serve all routes under with_virtual_dom
Evan Almloff hace 6 meses
padre
commit
3e1e7f05e7

+ 8 - 1
packages/liveview/src/adapters/axum_adapter.rs

@@ -62,6 +62,13 @@ impl LiveviewRouter for Router {
         };
 
         let app = Arc::new(app);
+        // Add an extra catch all segment to the route
+        let mut route = route.trim_matches('/').to_string();
+        if route.is_empty() {
+            route = "/*route".to_string();
+        } else {
+            route = format!("/{route}/*route");
+        }
 
         self.route(
             &ws_path,
@@ -75,7 +82,7 @@ impl LiveviewRouter for Router {
             }),
         )
         .route(
-            route,
+            &route,
             get(move || async move { index_page_with_glue(&interpreter_glue(&ws_path)) }),
         )
     }

+ 4 - 0
packages/liveview/src/history.rs

@@ -342,6 +342,10 @@ impl History for LiveviewHistory {
         let mut updater_callback = self.updater_callback.write().unwrap();
         *updater_callback = callback;
     }
+
+    fn include_prevent_default(&self) -> bool {
+        true
+    }
 }
 
 mod routes {