use crate::*;
pub(crate) fn current_route() -> String {
let window: Window = window().expect("no global window exists");
let hash: String = window.location().hash().unwrap_or_default();
let route: String = hash.strip_prefix('#').unwrap_or(&hash).to_string();
if route.is_empty() {
"/".to_string()
} else {
route
}
}
pub(crate) fn navigate(route: &str) {
let window: Window = window().expect("no global window exists");
let location: Location = window.location();
let new_hash: String = format!("#{}", route);
let _ = location.set_hash(&new_hash);
}
pub(crate) fn link_handler(route: String) -> NativeEventHandler {
NativeEventHandler::create(NativeEventName::Click, move |_event: Event| {
navigate(&route);
})
}
pub(crate) fn is_mobile() -> bool {
let window: Window = window().expect("no global window exists");
let width: f64 = window
.inner_width()
.ok()
.map(|v| Number::from(v).value_of())
.unwrap_or(0.0);
width < MOBILE_BREAKPOINT as f64
}