Files
mont-fort-app/src/main.rs
T
2026-05-06 09:21:40 +00:00

65 lines
1.6 KiB
Rust

mod components;
mod matterhorn;
use crate::components::views::{HelloMRidge};
use leptos::prelude::*;
use leptos::reactive::owner::Owner;
use leptos_router::components::{Route, Router, Routes};
use leptos_router::path;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
fn main() {
console_error_panic_hook::set_once();
mount_to_body(App);
}
/*
* App entrypoint; define new routes and add new components here.
* Hint: do not change the Router base and always ever use relative routes
*/
fn App() -> impl IntoView {
view! {
<Router base=get_base_path()>
<Routes fallback=|| view! { <p>"Not found"</p> }>
<Route path=path!("/") view=HelloMRidge/>
</Routes>
</Router>
}
}
/**
* DO NOT change this config retrieval method
*/
fn get_config() -> Option<(String, String)> {
let window = web_sys::window()?;
let config = js_sys::Reflect::get(&window, &"__appConfig".into()).ok()?;
let token = js_sys::Reflect::get(&config, &"token".into())
.ok()?
.as_string()?;
let user = js_sys::Reflect::get(&config, &"user".into())
.ok()?
.as_string()?;
Some((token, user))
}
/*
* Gets the base path for the web application
*/
pub fn get_base_path() -> String {
web_sys::window()
.and_then(|w| w.document())
.and_then(|d| d.query_selector("base").ok().flatten())
.and_then(|el| el.get_attribute("href"))
.unwrap_or_else(|| "/".to_string())
}
/*
* Gets the
*/
pub fn asset_path(file: &str) -> String {
format!("{}assets/{}", get_base_path(), file.trim_start_matches('/'))
}