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 empty web history prefixes #2621

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
13 changes: 8 additions & 5 deletions packages/router/src/history/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ impl<R: Routable> WebHistory<R> {
}

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()))
.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 {
do_scroll_restoration,
Expand Down Expand Up @@ -214,10 +220,7 @@ where
}

fn replace(&mut self, state: R) {
let path = match &self.prefix {
None => format!("{state}"),
Some(prefix) => format!("{prefix}{state}"),
};
let path = self.full_path(&state);

let state = self.create_state(state);
self.handle_nav(replace_state_with_url(&self.history, &state, Some(&path)));
Expand Down
Loading