Skip to content

Commit

Permalink
fix(router): prevent from throwing when browser pushes null state
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed May 14, 2024
1 parent a5645d6 commit 3208959
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function setupView(hybrids, routerOptions, parent, nestedParent) {
return params;
},
(host, params, lastParams) => {
if (!lastParams) return;
if (!lastParams || !globalThis.history.state) return;

const state = globalThis.history.state;
const index = state.findIndex((entry) => {
Expand Down
13 changes: 13 additions & 0 deletions test/spec/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,19 @@ describe("router:", () => {
});
});

it("does not throw when browser pushes null state", () => {
const state = window.history.state;
window.history.replaceState(null, "", "");
const rootView = host.views[0];
rootView.globalB = "value";

return resolveTimeout(() => {
expect(hybrids(host.views[0])).toBe(RootView);
expect(hybrids(host.children[0])).toBe(RootView);
window.history.replaceState(state, "", "");
});
});

it("displays root view", () =>
resolveTimeout(() => {
expect(hybrids(host.views[0])).toBe(RootView);
Expand Down

0 comments on commit 3208959

Please sign in to comment.