Skip to content

Commit

Permalink
Add debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Sep 12, 2024
1 parent 12b87d2 commit 34adaef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/yew-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::<String>::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`,
Expand All @@ -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()))
Expand Down
6 changes: 3 additions & 3 deletions packages/yew-router/tests/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);

Expand Down

0 comments on commit 34adaef

Please sign in to comment.