Skip to main content

euv_ui/component/router/
impl.rs

1use super::*;
2
3/// Inherent implementation of [`NestedRouteConfig`].
4impl NestedRouteConfig {
5    /// Creates a new nested route configuration.
6    ///
7    /// # Arguments
8    ///
9    /// - `impl Into<String>` - The route path.
10    /// - `F: Fn() -> VirtualNode + 'static` - The component closure.
11    /// - `Vec<NestedRouteConfig>` - The child
12    ///   routes.
13    pub fn new<P, F>(path: P, component: F, children: Vec<NestedRouteConfig>) -> Self
14    where
15        P: Into<String>,
16        F: Fn() -> VirtualNode + 'static,
17    {
18        Self {
19            path: path.into(),
20            component: Rc::new(component),
21            children,
22        }
23    }
24
25    /// Returns the component closure.
26    ///
27    /// # Returns
28    ///
29    /// - `Rc<dyn Fn() -> VirtualNode>` - A shared closure producing the route's component node.
30    pub fn component(&self) -> Rc<dyn Fn() -> VirtualNode> {
31        self.get_component().clone()
32    }
33
34    /// Returns the child routes.
35    ///
36    /// # Returns
37    ///
38    /// - `[NestedRouteConfig]` - Slice of all child route configs.
39    pub fn children(&self) -> &[NestedRouteConfig] {
40        self.get_children()
41    }
42}