Skip to content

Commit

Permalink
use base url for href of links (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldSEnder authored Nov 22, 2021
1 parent 3e656dd commit ae7a8be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/yew-router/src/components/link.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::borrow::Cow;
use std::marker::PhantomData;

use serde::Serialize;
use wasm_bindgen::UnwrapThrowExt;
use yew::prelude::*;
use yew::virtual_dom::AttrValue;

use crate::history::History;
use crate::history::{BrowserHistory, History};
use crate::scope_ext::RouterScopeExt;
use crate::Routable;

Expand Down Expand Up @@ -90,9 +92,13 @@ where
e.prevent_default();
Msg::OnClick
});
let href: AttrValue = match BrowserHistory::route_to_url(to) {
Cow::Owned(href) => href.into(),
Cow::Borrowed(href) => href.into(),
};
html! {
<a class={classes}
href={to.to_path()}
{href}
{onclick}
{disabled}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-router/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl BrowserHistory {
Self::default()
}

fn route_to_url(route: impl Routable) -> Cow<'static, str> {
pub(crate) fn route_to_url(route: impl Routable) -> Cow<'static, str> {
let base = base_url();
let url = route.to_path();

Expand Down

0 comments on commit ae7a8be

Please sign in to comment.