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();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use web_sys::{
|
|||
use crate::{
|
||||
modal_dialog, request,
|
||||
toast::{self, Level},
|
||||
utils::{SelectorExt, by_id, selector, selector_and_clone},
|
||||
utils::{SelectorExt, by_id, get_current_lang, selector, selector_and_clone},
|
||||
};
|
||||
|
||||
pub fn setup_page(recipe_id: i64) {
|
||||
|
|
@ -262,7 +262,10 @@ pub fn setup_page(recipe_id: i64) {
|
|||
{
|
||||
let body = ron_api::Id { id: recipe_id };
|
||||
let _ = request::delete::<(), _>("recipe/remove", body).await;
|
||||
window().location().set_href("/").unwrap();
|
||||
window()
|
||||
.location()
|
||||
.set_href(&format!("/{}/", get_current_lang()))
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue