aex/src/app.rs

72 lines
2.1 KiB
Rust
Raw Normal View History

2025-09-11 05:43:59 +00:00
use leptos::prelude::*;
use leptos_meta::{provide_meta_context, Stylesheet, Title};
use leptos_router::{
components::{Route, Router, Routes},
StaticSegment, WildcardSegment,
};
2025-09-11 21:44:46 +00:00
use crate::{ prelude::*, components::{ header::Header, Dash } };
2025-09-11 07:27:57 +00:00
2025-09-11 05:43:59 +00:00
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
2025-09-11 21:44:46 +00:00
provide_context(Store::new(Dashboard::mock()));
2025-09-11 05:43:59 +00:00
view! {
// injects a stylesheet into the document <head>
// id=leptos means cargo-leptos will hot-reload this stylesheet
<Stylesheet id="leptos" href="/pkg/aex.css"/>
// sets the document title
<Title text="Welcome to Leptos"/>
// content for this welcome page
<Router>
2025-09-11 21:44:46 +00:00
<Header />
<aside></aside>
2025-09-11 05:43:59 +00:00
<main>
<Routes fallback=move || "Not found.">
2025-09-11 07:27:57 +00:00
<Route path=StaticSegment("") view=Dash/>
2025-09-11 05:43:59 +00:00
<Route path=WildcardSegment("any") view=NotFound/>
</Routes>
</main>
</Router>
}
}
/// Renders the home page of your application.
#[component]
fn HomePage() -> impl IntoView {
// Creates a reactive value to update the button
let count = RwSignal::new(0);
let on_click = move |_| *count.write() += 1;
view! {
<h1>"Welcome to Leptos!"</h1>
<button on:click=on_click>"Click Me: " {count}</button>
}
}
/// 404 - Not Found
#[component]
fn NotFound() -> impl IntoView {
// set an HTTP status code 404
// this is feature gated because it can only be done during
// initial server-side rendering
// if you navigate to the 404 page subsequently, the status
// code will not be set because there is not a new HTTP request
// to the server
#[cfg(feature = "ssr")]
{
// this can be done inline because it's synchronous
// if it were async, we'd use a server function
let resp = expect_context::<leptos_actix::ResponseOptions>();
resp.set_status(actix_web::http::StatusCode::NOT_FOUND);
}
view! {
<h1>"Not Found"</h1>
}
}