浏览代码

fix: use ordering of routes for router

Jonathan Kelley 3 年之前
父节点
当前提交
cc4b073f0d
共有 2 个文件被更改,包括 20 次插入1 次删除
  1. 1 1
      packages/router/src/components/router.rs
  2. 19 0
      packages/router/src/service.rs

+ 1 - 1
packages/router/src/components/router.rs

@@ -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);
                     }
                 }

+ 19 - 0
packages/router/src/service.rs

@@ -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" }
+
+*/