mirror of
https://github.com/kristoferssolo/kristofersxyz-rs.git
synced 2025-10-21 20:10:36 +00:00
refactor: change components structure
This commit is contained in:
parent
44f586a369
commit
1f64283998
@ -19,3 +19,6 @@ thiserror.workspace = true
|
|||||||
default = []
|
default = []
|
||||||
hydrate = ["leptos/hydrate"]
|
hydrate = ["leptos/hydrate"]
|
||||||
ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", "dep:leptos_axum"]
|
ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", "dep:leptos_axum"]
|
||||||
|
|
||||||
|
[package.metadata.rust-analyzer]
|
||||||
|
diagnostics.disabled = ["non_snake_case"]
|
||||||
|
|||||||
30
app/src/components/app.rs
Normal file
30
app/src/components/app.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
use leptos::prelude::*;
|
||||||
|
use leptos_meta::{Stylesheet, Title, provide_meta_context};
|
||||||
|
use leptos_router::{
|
||||||
|
StaticSegment,
|
||||||
|
components::{Route, Router, Routes},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::components::home_page::HomePage;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn App() -> impl IntoView {
|
||||||
|
// Provides context that manages stylesheets, titles, meta tags, etc.
|
||||||
|
provide_meta_context();
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<Stylesheet id="leptos" href="/pkg/start-axum-workspace.css" />
|
||||||
|
|
||||||
|
// sets the document title
|
||||||
|
<Title text="Welcome to Leptos" />
|
||||||
|
|
||||||
|
// content for this welcome page
|
||||||
|
<Router>
|
||||||
|
<main>
|
||||||
|
<Routes fallback=|| "Page not found.".into_view()>
|
||||||
|
<Route path=StaticSegment("") view=HomePage />
|
||||||
|
</Routes>
|
||||||
|
</main>
|
||||||
|
</Router>
|
||||||
|
}
|
||||||
|
}
|
||||||
14
app/src/components/home_page.rs
Normal file
14
app/src/components/home_page.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use leptos::prelude::*;
|
||||||
|
|
||||||
|
/// Renders the home page of your application.
|
||||||
|
#[component]
|
||||||
|
pub 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>
|
||||||
|
}
|
||||||
|
}
|
||||||
4
app/src/components/mod.rs
Normal file
4
app/src/components/mod.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
pub mod app;
|
||||||
|
mod home_page;
|
||||||
|
|
||||||
|
pub use app::App;
|
||||||
@ -1,9 +1,8 @@
|
|||||||
|
mod components;
|
||||||
|
|
||||||
|
pub use components::App;
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title};
|
use leptos_meta::MetaTags;
|
||||||
use leptos_router::{
|
|
||||||
components::{Route, Router, Routes},
|
|
||||||
StaticSegment,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
@ -22,38 +21,3 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
|
|||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn App() -> impl IntoView {
|
|
||||||
// Provides context that manages stylesheets, titles, meta tags, etc.
|
|
||||||
provide_meta_context();
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<Stylesheet id="leptos" href="/pkg/start-axum-workspace.css"/>
|
|
||||||
|
|
||||||
// sets the document title
|
|
||||||
<Title text="Welcome to Leptos"/>
|
|
||||||
|
|
||||||
// content for this welcome page
|
|
||||||
<Router>
|
|
||||||
<main>
|
|
||||||
<Routes fallback=|| "Page not found.".into_view()>
|
|
||||||
<Route path=StaticSegment("") view=HomePage/>
|
|
||||||
</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>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user