mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 22:54:12 +00:00
Add more trace messages to the RouterService code
I was trying to debug some issues with my routes and this additional tracing was quite helpful.
This commit is contained in:
parent
d367e0f89f
commit
3a5b417ad1
2 changed files with 16 additions and 2 deletions
|
@ -30,6 +30,7 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
|
|||
Some(ctx) => ctx.total_route.to_string(),
|
||||
None => cx.props.to.to_string(),
|
||||
};
|
||||
log::trace!("total route for {} is {}", cx.props.to, total_route);
|
||||
|
||||
// provide our route context
|
||||
let route_context = cx.provide_context(RouteContext {
|
||||
|
|
|
@ -46,8 +46,8 @@ impl RouterService {
|
|||
let listener = history.listen(move || {
|
||||
_root_found.set(false);
|
||||
// checking if the route is valid is cheap, so we do it
|
||||
for (slot, _) in _slots.borrow_mut().iter().rev() {
|
||||
log::trace!("regenerating slot {:?}", slot);
|
||||
for (slot, root) in _slots.borrow_mut().iter().rev() {
|
||||
log::trace!("regenerating slot {:?} for root '{}'", slot, root);
|
||||
regen(*slot);
|
||||
}
|
||||
});
|
||||
|
@ -68,20 +68,25 @@ impl RouterService {
|
|||
}
|
||||
|
||||
pub fn push_route(&self, route: &str) {
|
||||
log::trace!("Pushing route: {}", route);
|
||||
self.history.borrow_mut().push(route);
|
||||
}
|
||||
|
||||
pub fn register_total_route(&self, route: String, scope: ScopeId, fallback: bool) {
|
||||
log::trace!("Registered route '{}' with scope id {:?}", route, scope);
|
||||
self.slots.borrow_mut().push((scope, route));
|
||||
}
|
||||
|
||||
pub fn should_render(&self, scope: ScopeId) -> bool {
|
||||
log::trace!("Should render scope id {:?}?", scope);
|
||||
if self.root_found.get() {
|
||||
log::trace!(" no - because root_found is true");
|
||||
return false;
|
||||
}
|
||||
|
||||
let location = self.history.borrow().location();
|
||||
let path = location.path();
|
||||
log::trace!(" current path is '{}'", path);
|
||||
|
||||
let roots = self.slots.borrow();
|
||||
|
||||
|
@ -90,14 +95,22 @@ impl RouterService {
|
|||
// fallback logic
|
||||
match root {
|
||||
Some((_id, route)) => {
|
||||
log::trace!(
|
||||
" matched given scope id {:?} with route root '{}'",
|
||||
scope,
|
||||
route,
|
||||
);
|
||||
if route == path {
|
||||
log::trace!(" and it matches the current path '{}'", path);
|
||||
self.root_found.set(true);
|
||||
true
|
||||
} else {
|
||||
if route == "" {
|
||||
log::trace!(" and the route is the root, so we will use that without a better match");
|
||||
self.root_found.set(true);
|
||||
true
|
||||
} else {
|
||||
log::trace!(" and the route '{}' is not the root nor does it match the current path", route);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue