Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduces the FromQuery and IntoQuery traits #3565

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/yew-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ pub mod history {
};
}

pub mod query {
//! A module that provides custom query serialization & deserialization.

pub use gloo::history::query:: {
ToQuery, FromQuery, Raw
};
}

pub mod prelude {
//! Prelude module to be imported when working with `yew-router`.
//!
Expand Down
23 changes: 11 additions & 12 deletions packages/yew-router/src/navigator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;

use serde::Serialize;

use crate::query::ToQuery;
use crate::history::{AnyHistory, History, HistoryError, HistoryResult};
use crate::routable::Routable;

Expand Down Expand Up @@ -93,20 +92,20 @@ impl Navigator {
}

/// Same as `.push()` but affix the queries to the end of the route.
pub fn push_with_query<R, Q>(&self, route: &R, query: &Q) -> NavigationResult<()>
pub fn push_with_query<R, Q>(&self, route: &R, query: Q) -> Result<(), Q::Error>
where
R: Routable,
Q: Serialize,
Q: ToQuery,
{
self.inner
.push_with_query(self.prefix_basename(&route.to_path()), query)
}

/// Same as `.replace()` but affix the queries to the end of the route.
pub fn replace_with_query<R, Q>(&self, route: &R, query: &Q) -> NavigationResult<()>
pub fn replace_with_query<R, Q>(&self, route: &R, query: Q) -> Result<(), Q::Error>
where
R: Routable,
Q: Serialize,
Q: ToQuery,
{
self.inner
.replace_with_query(self.prefix_basename(&route.to_path()), query)
Expand All @@ -116,12 +115,12 @@ impl Navigator {
pub fn push_with_query_and_state<R, Q, T>(
&self,
route: &R,
query: &Q,
query: Q,
state: T,
) -> NavigationResult<()>
) -> Result<(), Q::Error>
where
R: Routable,
Q: Serialize,
Q: ToQuery,
T: 'static,
{
self.inner
Expand All @@ -132,12 +131,12 @@ impl Navigator {
pub fn replace_with_query_and_state<R, Q, T>(
&self,
route: &R,
query: &Q,
query: Q,
state: T,
) -> NavigationResult<()>
) -> Result<(), Q::Error>
where
R: Routable,
Q: Serialize,
Q: ToQuery,
T: 'static,
{
self.inner.replace_with_query_and_state(
Expand Down
Loading