Skip to content

Commit 90b3a99

Browse files
committed
fix(i18n): 🐛 made locale redirection work without trailing forward slash
Formatting irregularities can easily be caused by them, now that's handled.
1 parent 3b3dae5 commit 90b3a99

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/perseus/src/locale_detector.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ pub fn detect_locale(url: String, locales: Locales) {
4040
// Figure out what the new localized route should be
4141
// This is complex because we need to strip away the base path
4242
// We use the pathname part of the URL because the base path getter gets the pathname too
43+
let url = url.strip_suffix('/').unwrap_or(&url);
44+
let url = url.strip_prefix('/').unwrap_or(url);
45+
let url = format!("/{}", url);
4346
let base_path = get_path_prefix_client(); // We know this doesn't have a trailing slash
4447
let loc = url.strip_prefix(&base_path).unwrap_or(&url);
4548
let new_loc = format!("{}/{}/{}", base_path, locale, loc);
49+
let new_loc = new_loc.strip_suffix('/').unwrap_or(&new_loc);
4650

4751
// Imperatively navigate to the localized route
4852
// This certainly shouldn't fail...
4953
web_sys::window()
5054
.unwrap()
5155
.location()
52-
.replace(&new_loc)
56+
.replace(new_loc)
5357
.unwrap();
5458
}
5559

0 commit comments

Comments
 (0)