Improve the base_path story (#2381)
* Improve the base_path story * allow base path routes without trailing slash * remove note about trailing / * fix clippy empty docs --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
472031d1f5
commit
010dcf9533
6 files changed
+31
-21
No files matched your search
@@ -74,7 +74,9 @@ impl<R: Routable> WebHistory<R> {
|
||||
let myself = Self::new_inner(prefix, do_scroll_restoration);
|
||||
|
||||
let current_route = myself.current_route();
|
||||
let current_url = current_route.to_string();
|
||||
let current_route_str = current_route.to_string();
|
||||
let prefix_str = myself.prefix.as_deref().unwrap_or("");
|
||||
let current_url = format!("{prefix_str}{current_route_str}");
|
||||
let state = myself.create_state(current_route);
|
||||
let _ = replace_state_with_url(&myself.history, &state, Some(¤t_url));
|
||||
|
||||
@@ -130,17 +132,15 @@ where
|
||||
let path = location.pathname().unwrap_or_else(|_| "/".into())
|
||||
+ &location.search().unwrap_or("".into())
|
||||
+ &location.hash().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
|
||||
}
|
||||
}
|
||||
let mut path = match self.prefix {
|
||||
None => &path,
|
||||
Some(ref prefix) => path.strip_prefix(prefix).unwrap_or(prefix),
|
||||
};
|
||||
R::from_str(&path).unwrap_or_else(|err| panic!("{}", err))
|
||||
// If the path is empty, parse the root route instead
|
||||
if path.is_empty() {
|
||||
path = "/"
|
||||
}
|
||||
R::from_str(path).unwrap_or_else(|err| panic!("{}", err))
|
||||
}
|
||||
|
||||
fn full_path(&self, state: &R) -> String {
|
||||
|
||||
Reference in new issue
Block a user