Skip to content

Commit edca6ce

Browse files
authored
Merge pull request #424 from piotr-cz/bugfix/preact-iso/router/pushstate
(preact-iso): Router: Fix change location after useLocation().route()
2 parents 24417f6 + 0bbb8cc commit edca6ce

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/sharp-cats-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-iso': patch
3+
---
4+
5+
Set default value for push to true

packages/preact-iso/router.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { h, createContext, cloneElement } from 'preact';
22
import { useContext, useMemo, useReducer, useEffect, useLayoutEffect, useRef } from 'preact/hooks';
33

4-
const UPDATE = (state, url, push) => {
4+
const UPDATE = (state, url) => {
5+
let push = true;
56
if (url && url.type === 'click') {
67
const link = url.target.closest('a[href]');
78
if (!link || link.origin != location.origin) return state;
89

910
url.preventDefault();
10-
push = true;
1111
url = link.href.replace(location.origin, '');
1212
} else if (typeof url !== 'string') {
1313
url = location.pathname + location.search;
14+
push = undefined;
1415
}
1516

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

0 commit comments

Comments
 (0)