use a default base path for the web router from the config

This commit is contained in:
Evan Almloff committed 2023-11-14 16:49:06 -06:00
1 parent 15984b78db
commit 109e10e406
2 files changed
+23 -1

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ gloo-utils = { version = "0.1.6", optional = true }
dioxus-liveview = { workspace = true, optional = true } dioxus-liveview = { workspace = true, optional = true }
dioxus-ssr = { workspace = true, optional = true } dioxus-ssr = { workspace = true, optional = true }
tokio = { workspace = true, features = ["full"], optional = true } tokio = { workspace = true, features = ["full"], optional = true }
dioxus-cli-config.workspace = true
[features] [features]
default = ["web"] default = ["web"]
+22 -1
View File
@@ -13,6 +13,17 @@ use super::{
HistoryProvider, HistoryProvider,
}; };
#[allow(dead_code)]
fn base_path() -> Option<&'static str> {
dioxus_cli_config::CURRENT_CONFIG.as_ref().ok().and_then(|c| {
c.dioxus_config
.web
.app
.base_path
.as_deref()
})
}
#[cfg(not(feature = "serde"))] #[cfg(not(feature = "serde"))]
#[allow(clippy::extra_unused_type_parameters)] #[allow(clippy::extra_unused_type_parameters)]
fn update_scroll<R>(window: &Window, history: &History) { fn update_scroll<R>(window: &Window, history: &History) {
@@ -165,7 +176,7 @@ impl<R: Routable> WebHistory<R> {
history, history,
listener_navigation: None, listener_navigation: None,
listener_animation_frame: Default::default(), listener_animation_frame: Default::default(),
prefix, prefix: prefix.or_else(||base_path().map(|s| s.to_string())),
window, window,
phantom: Default::default(), phantom: Default::default(),
} }
@@ -198,6 +209,16 @@ where
let location = self.window.location(); let location = self.window.location();
let path = location.pathname().unwrap_or_else(|_| "/".into()) let path = location.pathname().unwrap_or_else(|_| "/".into())
+ &location.search().unwrap_or("".into()); + &location.search().unwrap_or("".into());
let path = match self.prefix {
None => path,
Some(ref prefix) => {
if path.starts_with(prefix) {
path[prefix.len()..].to_string()
} else {
path
}
}
};
R::from_str(&path).unwrap_or_else(|err| panic!("{}", err)) R::from_str(&path).unwrap_or_else(|err| panic!("{}", err))
} }