Skip to content

Commit

Permalink
fix(router): add view to the stack of all parents
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Dec 19, 2023
1 parent 1c8f867 commit f0cbe51
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ function setupView(hybrids, routerOptions, parent, nestedParent) {
} else {
config.parent = parent;
config.nestedParent = nestedParent;

if (parent && !parent.stack.includes(config)) {
parent.stack.push(config);
}
}

if (!parent) {
Expand Down Expand Up @@ -1123,7 +1127,7 @@ function router(views, options) {

console.groupEnd();

global[`$$${key}`] = view;
globalThis[`$$${key}`] = view;
}),
};

Expand Down
43 changes: 43 additions & 0 deletions test/spec/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,49 @@ describe("router:", () => {
});
});

it("uses push navigation to view with multiple parents", () => {
const Target = define({
tag: "test-router-view-multiple-parents-target",
});

const A = define({
tag: "test-router-view-multiple-parents-a",
[router.connect]: {
stack: [Target],
},
content: () => html` <a href="${router.url(B)}"></a> `,
});

const B = define({
tag: "test-router-view-multiple-parents-b",
[router.connect]: {
stack: [Target],
},
content: () => html` <a href="${router.url(Target)}"></a> `,
});

define({
tag: "test-router-view-multiple-parents",
stack: router([A, B]),
content: ({ stack }) => html`${stack}`,
});

const el = document.createElement("test-router-view-multiple-parents");
document.body.appendChild(el);

return resolveTimeout(() => {
el.querySelector("a").click();
return resolveTimeout(() => {
el.querySelector("a").click();

return resolveTimeout(() => {
expect(history.state.length).toBe(2);
document.body.removeChild(el);
});
});
});
});

describe("test app", () => {
beforeAll(() => {
NestedViewTwo = define({
Expand Down

0 comments on commit f0cbe51

Please sign in to comment.