diff --git a/examples/router/src/pages/post_list.rs b/examples/router/src/pages/post_list.rs
index 7f6b21cd001..1f52e0a94a6 100644
--- a/examples/router/src/pages/post_list.rs
+++ b/examples/router/src/pages/post_list.rs
@@ -2,6 +2,7 @@ use crate::components::{pagination::Pagination, post_card::PostCard};
use crate::Route;
use serde::{Deserialize, Serialize};
use yew::prelude::*;
+use yew_router::prelude::*;
const ITEMS_PER_PAGE: u64 = 10;
const TOTAL_PAGES: u64 = u64::MAX / ITEMS_PER_PAGE;
@@ -25,23 +26,27 @@ impl Component for PostList {
Self
}
- fn update(&mut self, _ctx: &Context{ "Posts" }
{ "All of our quality writing in one place" }
- { self.view_posts() }
+ { self.view_posts(ctx) }
(&self, route: impl Routable, query: Q) -> HistoryResult<()>
+ where
+ Q: Serialize;
+
+ /// Same as `.replace()` but affix the queries to the end of the route.
+ fn replace_with_query
(&self, route: impl Routable, query: Q) -> HistoryResult<()>
+ where
+ Q: Serialize;
+
+ /// Same as `.push_with_state()` but affix the queries to the end of the route.
+ fn push_with_query_and_state
(
+ &self,
+ route: impl Routable,
+ query: Q,
+ state: T,
+ ) -> HistoryResult<()>
+ where
+ Q: Serialize,
+ T: Serialize + 'static;
+
+ /// Same as `.replace_with_state()` but affix the queries to the end of the route.
+ fn replace_with_query_and_state
(
+ &self,
+ route: impl Routable,
+ query: Q,
+ state: T,
+ ) -> HistoryResult<()>
+ where
+ Q: Serialize,
+ T: Serialize + 'static;
+
+ /// Creates a Listener that will be notified when current state changes.
+ ///
+ /// This method returns a [`HistoryListener`] that will automatically unregister the callback
+ /// when dropped.
+ fn listen
(&self, route: impl Routable, query: Q) -> HistoryResult<()>
+ where
+ Q: Serialize,
+ {
+ let url = Self::route_to_url(route);
+ let query = serde_urlencoded::to_string(query)?;
+ self.inner
+ .push_state_with_url(&JsValue::NULL, "", Some(&format!("{}?{}", url, query)))
+ .expect("failed to push history.");
+
+ self.notify_callbacks();
+ Ok(())
+ }
+ fn replace_with_query
(&self, route: impl Routable, query: Q) -> HistoryResult<()>
+ where
+ Q: Serialize,
+ {
+ let url = Self::route_to_url(route);
+ let query = serde_urlencoded::to_string(query)?;
+ self.inner
+ .replace_state_with_url(&JsValue::NULL, "", Some(&format!("{}?{}", url, query)))
+ .expect("failed to replace history.");
+
+ self.notify_callbacks();
+ Ok(())
+ }
+
+ fn push_with_query_and_state
(
+ &self,
+ route: impl Routable,
+ query: Q,
+ state: T,
+ ) -> HistoryResult<()>
+ where
+ Q: Serialize,
+ T: Serialize + 'static,
+ {
+ let url = Self::route_to_url(route);
+ let query = serde_urlencoded::to_string(query)?;
+ let state = serde_wasm_bindgen::to_value(&state)?;
+ self.inner
+ .push_state_with_url(&state, "", Some(&format!("{}?{}", url, query)))
+ .expect("failed to push history.");
+
+ self.notify_callbacks();
+ Ok(())
+ }
+
+ fn replace_with_query_and_state
(
+ &self,
+ route: impl Routable,
+ query: Q,
+ state: T,
+ ) -> HistoryResult<()>
+ where
+ Q: Serialize,
+ T: Serialize + 'static,
+ {
+ let url = Self::route_to_url(route);
+ let query = serde_urlencoded::to_string(query)?;
+ let state = serde_wasm_bindgen::to_value(&state)?;
+ self.inner
+ .replace_state_with_url(&state, "", Some(&format!("{}?{}", url, query)))
+ .expect("failed to replace history.");
+
+ self.notify_callbacks();
+ Ok(())
+ }
+
+ fn listen