Switch over to WebAssembly, Rust and Yew #35

Merged
BlakeRain merged 87 commits from yew-static into main 2023-08-30 18:01:40 +00:00
2 changed files with 18 additions and 1 deletions
Showing only changes of commit d4a05eca17 - Show all commits

View File

@ -72,6 +72,7 @@ features = [
"Element", "Element",
"IntersectionObserver", "IntersectionObserver",
"IntersectionObserverEntry", "IntersectionObserverEntry",
"ScrollBehavior",
"ScrollToOptions", "ScrollToOptions",
"Window" "Window"
] ]

View File

@ -1,4 +1,6 @@
use yew::{function_component, html, Children, Html, Properties}; use web_sys::{window, ScrollBehavior, ScrollToOptions};
use yew::{function_component, html, use_effect_with_deps, Children, Html, Properties};
use yew_router::prelude::use_location;
mod footer; mod footer;
pub mod goto_top; pub mod goto_top;
@ -13,6 +15,20 @@ pub struct LayoutProps {
#[function_component(Layout)] #[function_component(Layout)]
pub fn layout(props: &LayoutProps) -> Html { pub fn layout(props: &LayoutProps) -> Html {
let location = use_location();
use_effect_with_deps(
|_| {
let mut opts = ScrollToOptions::new();
opts.top(0f64);
opts.behavior(ScrollBehavior::Instant);
window()
.expect("window")
.scroll_to_with_scroll_to_options(&opts);
},
location,
);
html! { html! {
<div class="flex flex-col"> <div class="flex flex-col">
<navigation::Navigation /> <navigation::Navigation />