freya_router/router_cfg.rs
1use crate::prelude::Routable;
2
3/// Global configuration options for the router.
4///
5/// This implements [`Default`] and follows the builder pattern, so you can use it like this:
6/// ```rust,no_run
7/// # use freya_router::prelude::*;
8/// # use freya_core::prelude::*;
9/// # #[derive(PartialEq)]
10/// # struct Index;
11/// # impl Render for Index {
12/// # fn render(&self) -> impl IntoElement {
13/// # rect()
14/// # }
15/// # }
16/// #[derive(Clone, Routable)]
17/// enum Route {
18/// #[route("/")]
19/// Index {},
20/// }
21///
22/// let cfg = RouterConfig::<Route>::default().with_initial_path(Route::Index {});
23/// ```
24pub struct RouterConfig<R: Routable> {
25 pub(crate) initial_path: Option<R>,
26}
27
28impl<R: Routable> Default for RouterConfig<R> {
29 fn default() -> Self {
30 Self { initial_path: None }
31 }
32}
33
34impl<R: Routable> RouterConfig<R> {
35 pub fn with_initial_path(mut self, initial_path: R) -> Self {
36 self.initial_path = Some(initial_path);
37 self
38 }
39}