Skip to content

Commit

Permalink
fix(i18n): 🐛 made locale redirection work without trailing forward slash
Browse files Browse the repository at this point in the history
Formatting irregularities can easily be caused by them, now that's handled.
  • Loading branch information
arctic-hen7 committed Oct 7, 2021
1 parent 3b3dae5 commit 90b3a99
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/perseus/src/locale_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ pub fn detect_locale(url: String, locales: Locales) {
// Figure out what the new localized route should be
// This is complex because we need to strip away the base path
// We use the pathname part of the URL because the base path getter gets the pathname too
let url = url.strip_suffix('/').unwrap_or(&url);
let url = url.strip_prefix('/').unwrap_or(url);
let url = format!("/{}", url);
let base_path = get_path_prefix_client(); // We know this doesn't have a trailing slash
let loc = url.strip_prefix(&base_path).unwrap_or(&url);
let new_loc = format!("{}/{}/{}", base_path, locale, loc);
let new_loc = new_loc.strip_suffix('/').unwrap_or(&new_loc);

// Imperatively navigate to the localized route
// This certainly shouldn't fail...
web_sys::window()
.unwrap()
.location()
.replace(&new_loc)
.replace(new_loc)
.unwrap();
}

Expand Down

0 comments on commit 90b3a99

Please sign in to comment.