diff --git a/packages/yew-router/src/router.rs b/packages/yew-router/src/router.rs index ea92c53bd90..b4c46a66613 100644 --- a/packages/yew-router/src/router.rs +++ b/packages/yew-router/src/router.rs @@ -2,6 +2,7 @@ use std::borrow::Cow; use std::rc::Rc; +use gloo::console::console_dbg; use yew::prelude::*; use yew::virtual_dom::AttrValue; @@ -82,8 +83,10 @@ fn base_router(props: &RouterProps) -> Html { let navigator = navigator.clone(); let basename = basename.clone(); let old_basename = use_state_eq(|| Option::::None); + console_dbg!("render"); // Can't use `use_Effect_with` since need to track old and new, not just new. use_effect(move || { + console_dbg!("{basename:?} {:?}", *old_basename); if basename != *old_basename { // If `old_basename` is `Some`, path is probably prefixed with `old_basename`. // If `old_basename` is `None`, path may or may not be prefixed with the new `basename`, @@ -96,6 +99,7 @@ fn base_router(props: &RouterProps) -> Html { let location = history.location(); let stripped = old_navigator.strip_basename(Cow::from(location.path())); let prefixed = navigator.prefix_basename(&stripped); + console_dbg!("s {stripped} {prefixed}"); if prefixed != location.path() { history .replace_with_query(prefixed, Raw(location.query_str())) diff --git a/packages/yew-router/tests/link.rs b/packages/yew-router/tests/link.rs index e39848cc081..f9ed837ed03 100644 --- a/packages/yew-router/tests/link.rs +++ b/packages/yew-router/tests/link.rs @@ -172,18 +172,18 @@ async fn link_with_basename() { // Some(a) -> Some(b) handle.update(BasenameProps { - basename: Some("/based/".to_owned()), + basename: Some("/bayes/".to_owned()), }); sleep(Duration::ZERO).await; assert_eq!( - "/based/", + "/bayes/", gloo::utils::window().location().pathname().unwrap() ); assert_eq!( - "/based/posts", + "/bayes/posts", link_href("#with-basename ul > li.posts > a") );