(resolve => queueMicrotask(() => resolve()));
@@ -236,6 +242,62 @@ describe("Client navigation should", () => {
}
});
+ test("preserve parent layouts when navigating between sibling child routes (#588)", async () => {
+ const div = document.createElement("div");
+ document.body.appendChild(div);
+
+ let mounts = 0;
+ let navigate!: Navigator;
+
+ const Layout = (props: { children?: any }) => {
+ mounts++;
+ navigate = useNavigate();
+ return (
+
+ layout
+ {props.children}
+
+ );
+ };
+
+ const Router = createRouter({
+ routes: [
+ {
+ path: "/",
+ component: Layout,
+ children: [
+ { path: "/a", component: () => A
},
+ { path: "/b", component: () => B
}
+ ]
+ }
+ ] as const,
+ history: memoryHistory("/a")
+ });
+
+ const dispose = render(() => , div);
+
+ try {
+ await settle();
+ expect(mounts).toBe(1);
+ expect(div.querySelector('[data-route="a"]')?.textContent).toBe("A");
+
+ navigate("/b");
+ await settle();
+ expect(mounts).toBe(1);
+ expect(div.querySelector('[data-route="b"]')?.textContent).toBe("B");
+ expect(div.querySelector('[data-route="a"]')).toBeNull();
+
+ navigate("/a");
+ await settle();
+ expect(mounts).toBe(1);
+ expect(div.querySelector('[data-route="a"]')?.textContent).toBe("A");
+ expect(div.querySelector('[data-route="b"]')).toBeNull();
+ } finally {
+ dispose();
+ div.remove();
+ }
+ });
+
test("call preload with the route's own params during navigation", async () => {
const div = document.createElement("div");
document.body.appendChild(div);