Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Internal Links with Base Path and Enable External Links Without Modifier #2983

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/router/src/components/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/router/src/contexts/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl RouterContext {
failure_external_navigation: cfg.failure_external_navigation,

any_route_to_string: |route| {
route
let path = route
.downcast_ref::<R>()
.unwrap_or_else(|| {
panic!(
Expand All @@ -144,8 +144,13 @@ impl RouterContext {
route.type_id(),
std::any::TypeId::of::<R>()
)
})
.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,
Expand Down
Loading