Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(preact-iso): Router: Fix change location after useLocation().route() #424

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-cats-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-iso': patch
---

Set default value for push to true
5 changes: 3 additions & 2 deletions packages/preact-iso/router.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { h, createContext, cloneElement } from 'preact';
import { useContext, useMemo, useReducer, useEffect, useLayoutEffect, useRef } from 'preact/hooks';

const UPDATE = (state, url, push) => {
const UPDATE = (state, url) => {
let push = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we get to the else if (push === false) history.replaceState(null, '', url); now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot. however we never could (the UPDATE method is not exported, just the route(url) is). Now it's just obvious to notice.
Please read this PR description for explanation and try to get to evaluate history.replaceState on master branch if you can.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, #413 will provide a way to use push.

if (url && url.type === 'click') {
const link = url.target.closest('a[href]');
if (!link || link.origin != location.origin) return state;

url.preventDefault();
push = true;
url = link.href.replace(location.origin, '');
} else if (typeof url !== 'string') {
url = location.pathname + location.search;
push = undefined;
}

if (push === true) history.pushState(null, '', url);
Expand Down