From 2198933908a29f5cdcb7a18aad5115b312eb0214 Mon Sep 17 00:00:00 2001 From: LeWimbes <12753781+LeWimbes@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:31:52 +0200 Subject: [PATCH 1/2] make router links work with base_path --- packages/router/src/contexts/router.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/router/src/contexts/router.rs b/packages/router/src/contexts/router.rs index 26341b07e2..19ee7b1dc1 100644 --- a/packages/router/src/contexts/router.rs +++ b/packages/router/src/contexts/router.rs @@ -135,7 +135,7 @@ impl RouterContext { failure_external_navigation: cfg.failure_external_navigation, any_route_to_string: |route| { - route + let path = route .downcast_ref::() .unwrap_or_else(|| { panic!( @@ -144,8 +144,13 @@ impl RouterContext { route.type_id(), std::any::TypeId::of::() ) - }) - .to_string() + }); + + if let Some(base_path) = dioxus_cli_config::BASE_PATH { + format!("/{base_path}{path}") + } else { + path.to_string() + } }, site_map: R::SITE_MAP, From d3b77cb32348e009fe1aec43dc804079acadc380 Mon Sep 17 00:00:00 2001 From: LeWimbes <12753781+LeWimbes@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:32:37 +0200 Subject: [PATCH 2/2] make external links usable without modifier --- packages/router/src/components/link.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/router/src/components/link.rs b/packages/router/src/components/link.rs index c8054cfcde..501aeb65fb 100644 --- a/packages/router/src/components/link.rs +++ b/packages/router/src/components/link.rs @@ -264,11 +264,15 @@ pub fn Link(props: LinkProps) -> Element { let do_default = onclick.is_none() || !onclick_only; let action = move |event: MouseEvent| { + // Only handle internal links + if is_external { + return; + } // Only handle events without modifiers if !event.modifiers().is_empty() { return; } - // only handle left clicks + // Only handle left clicks if event.trigger_button() != Some(dioxus_elements::input_data::MouseButton::Primary) { return; }