Add the lang prefix to all links
This commit is contained in:
parent
b39cb1c067
commit
3089ede6eb
7 changed files with 40 additions and 11 deletions
|
|
@ -25,12 +25,19 @@ pub fn main() -> Result<(), JsValue> {
|
|||
let lang = utils::get_current_lang();
|
||||
|
||||
let location = window().location().pathname()?;
|
||||
|
||||
let path: Vec<&str> = location
|
||||
.split('/')
|
||||
.skip(1)
|
||||
.skip_while(|part| *part == lang)
|
||||
.collect();
|
||||
|
||||
let mut location_without_lang = String::new();
|
||||
for part in &path {
|
||||
location_without_lang.push('/');
|
||||
location_without_lang.push_str(part);
|
||||
}
|
||||
|
||||
let is_user_logged = selector::<HtmlElement>("html")
|
||||
.dataset()
|
||||
.get("userLogged")
|
||||
|
|
@ -54,10 +61,20 @@ pub fn main() -> Result<(), JsValue> {
|
|||
let select_language: HtmlSelectElement = by_id("select-website-language");
|
||||
EventListener::new(&select_language.clone(), "input", move |_event| {
|
||||
let lang = select_language.value();
|
||||
let body = ron_api::SetLang { lang };
|
||||
let body = ron_api::SetLang { lang: lang.clone() };
|
||||
let location_without_lang = location_without_lang.clone();
|
||||
spawn_local(async move {
|
||||
let _ = request::put::<(), _>("set_lang", body).await;
|
||||
let _ = window().location().reload();
|
||||
|
||||
window()
|
||||
.location()
|
||||
.set_href(&format!(
|
||||
"/{}{}{}",
|
||||
lang,
|
||||
location_without_lang,
|
||||
window().location().search().unwrap().as_str()
|
||||
))
|
||||
.unwrap();
|
||||
});
|
||||
})
|
||||
.forget();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue