mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
feat: optimized routing
This commit is contained in:
parent
9e433c5e67
commit
4a4b1bdf5c
2 changed files with 100 additions and 103 deletions
|
@ -13,33 +13,43 @@ use thaw::*;
|
|||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
let is_routing = RwSignal::new(false);
|
||||
let set_is_routing = SignalSetter::map(move |is_routing_data| {
|
||||
is_routing.set(is_routing_data);
|
||||
});
|
||||
provide_meta_context();
|
||||
// let (read_theme, _, _) = use_local_storage::<String, FromToStringCodec>("theme");
|
||||
// let theme = RwSignal::new(Theme::from(read_theme.get_untracked()));
|
||||
|
||||
view! {
|
||||
<Router set_is_routing>
|
||||
<TheProvider>
|
||||
<TheRouter is_routing/>
|
||||
</TheProvider>
|
||||
</Router>
|
||||
<ConfigProvider>
|
||||
<ToasterProvider>
|
||||
<LoadingBarProvider>
|
||||
<TheRouter />
|
||||
</LoadingBarProvider>
|
||||
</ToasterProvider>
|
||||
</ConfigProvider>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
|
||||
fn TheRouter() -> impl IntoView {
|
||||
let loading_bar = LoadingBarInjection::expect_use();
|
||||
_ = is_routing.watch(move |is_routing| {
|
||||
let is_routing = RwSignal::new(false);
|
||||
let set_is_routing = SignalSetter::map(move |is_routing_data| {
|
||||
is_routing.set(is_routing_data);
|
||||
});
|
||||
|
||||
Effect::watch(
|
||||
move || is_routing.get(),
|
||||
move |is_routing, _, _| {
|
||||
if *is_routing {
|
||||
loading_bar.start();
|
||||
} else {
|
||||
loading_bar.finish();
|
||||
}
|
||||
});
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
view! {
|
||||
<Router set_is_routing>
|
||||
<Routes fallback=|| "404">
|
||||
<Route path=path!("/") view=Home/>
|
||||
<ParentRoute path=path!("/guide") view=ComponentsPage>
|
||||
|
@ -108,21 +118,6 @@ fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
|
|||
}
|
||||
</ParentRoute>
|
||||
</Routes>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn TheProvider(children: Children) -> impl IntoView {
|
||||
// let (read_theme, _, _) = use_local_storage::<String, FromToStringCodec>("theme");
|
||||
// let theme = RwSignal::new(Theme::from(read_theme.get_untracked()));
|
||||
|
||||
view! {
|
||||
<ConfigProvider>
|
||||
<ToasterProvider>
|
||||
<LoadingBarProvider>
|
||||
{children()}
|
||||
</LoadingBarProvider>
|
||||
</ToasterProvider>
|
||||
</ConfigProvider>
|
||||
</Router>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,11 @@ fn main() {
|
|||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
view! {
|
||||
<ConfigProvider>
|
||||
<Button appearance=ButtonAppearance::Primary>
|
||||
"Primary"
|
||||
</Button>
|
||||
</ConfigProvider>
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Add table
Reference in a new issue