Fix empty prefixes (#2621)
This commit is contained in:
1 parent
b13236cd38
commit
96450a110e
1 file changed
+8
-5
@@ -96,8 +96,14 @@ impl<R: Routable> WebHistory<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let prefix = prefix
|
let prefix = prefix
|
||||||
|
// If there isn't a base path, try to grab one from the CLI
|
||||||
.or_else(|| base_path().map(|s| s.to_string()))
|
.or_else(|| base_path().map(|s| s.to_string()))
|
||||||
.map(|prefix| format!("/{}", prefix.trim_matches('/')));
|
// Normalize the prefix to start and end with no slashes
|
||||||
|
.map(|prefix| prefix.trim_matches('/').to_string())
|
||||||
|
// If the prefix is empty, don't add it
|
||||||
|
.filter(|prefix| !prefix.is_empty())
|
||||||
|
// Otherwise, start with a slash
|
||||||
|
.map(|prefix| format!("/{prefix}"));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
do_scroll_restoration,
|
do_scroll_restoration,
|
||||||
@@ -214,10 +220,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn replace(&mut self, state: R) {
|
fn replace(&mut self, state: R) {
|
||||||
let path = match &self.prefix {
|
let path = self.full_path(&state);
|
||||||
None => format!("{state}"),
|
|
||||||
Some(prefix) => format!("{prefix}{state}"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let state = self.create_state(state);
|
let state = self.create_state(state);
|
||||||
self.handle_nav(replace_state_with_url(&self.history, &state, Some(&path)));
|
self.handle_nav(replace_state_with_url(&self.history, &state, Some(&path)));
|
||||||
|
|||||||
Reference in new issue
Block a user