Skip to main content

auric_runtime/routing/
router.rs

1use super::RouteDef;
2use anyhow::Result;
3use std::sync::Arc;
4use web_sys::window;
5
6#[derive(Clone)]
7pub struct Router {
8    #[allow(unused)]
9    router: Arc<actix_router::Router<RouteDef>>,
10}
11
12impl Router {
13    pub fn new(route_defs: &[RouteDef]) -> Self {
14        let mut builder = actix_router::Router::build();
15        for route_def in route_defs.iter() {
16            builder.path(&route_def.path, route_def.clone());
17        }
18        let router = Arc::new(builder.finish());
19        Self { router }
20    }
21
22    pub fn init(&self) -> Result<()> {
23        // Find route for href
24        let _href = window()
25            .and_then(|win| win.location().href().ok())
26            .expect("Could not access window location");
27        // TODO
28
29        // Enter route
30        // TODO
31
32        // Done
33        web_sys::console::log_1(&"Initialized router".into());
34        Ok(())
35    }
36}