소스 검색

Fix client side liveview links (#3341)

* Fix liveview links

* Serve all routes under with_virtual_dom
Evan Almloff 6 달 전
부모
커밋
3e1e7f05e7
2개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 1
      packages/liveview/src/adapters/axum_adapter.rs
  2. 4 0
      packages/liveview/src/history.rs

+ 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 {