fix: use ordering of routes for router

This commit is contained in:
Jonathan Kelley 2022-03-09 17:50:39 -05:00
parent 0ce326566e
commit cc4b073f0d
2 changed files with 20 additions and 1 deletions

View file

@ -101,7 +101,7 @@ pub fn Router<'a>(cx: Scope<'a, RouterProps<'a>>) -> Element {
regen_route(*listener);
}
for route in svc.slots.borrow().keys() {
for route in svc.ordering.borrow().iter().rev() {
regen_route(*route);
}
}

View file

@ -49,6 +49,8 @@ pub struct RouterCore {
pub(crate) slots: Rc<RefCell<HashMap<ScopeId, String>>>,
pub(crate) ordering: Rc<RefCell<Vec<ScopeId>>>,
pub(crate) onchange_listeners: Rc<RefCell<HashSet<ScopeId>>>,
pub(crate) history: Box<dyn RouterProvider>,
@ -102,6 +104,7 @@ impl RouterCore {
tx,
route_found: Cell::new(None),
stack: RefCell::new(vec![route]),
ordering: Default::default(),
slots: Default::default(),
onchange_listeners: Default::default(),
history,
@ -167,6 +170,7 @@ impl RouterCore {
pub(crate) fn register_total_route(&self, route: String, scope: ScopeId) {
let clean = clean_route(route);
self.slots.borrow_mut().insert(scope, clean);
self.ordering.borrow_mut().push(scope);
}
pub(crate) fn should_render(&self, scope: ScopeId) -> bool {
@ -366,3 +370,18 @@ mod web {
}
}
}
/*
Route { to: "/blog/:id" }
Route { to: "/blog/:id" }
Route { to: "/blog/:id" }
Route { to: "/blog/:id" }
Route { to: "/blog/:id" }
*/