Skip to content

Commit d434f69

Browse files
committed
Fixes to programmaticNavigate
1 parent 66eacd6 commit d434f69

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

example/react-router-v6/src/AppNavData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const routeMapping = activator({
9393
salutation: "string",
9494
display: "myCustomRecord",
9595
},
96-
programmaticNavigate: false, // only read the query params for this route when naviating programmatically if set to true
96+
programmaticNavigate: true, // only read the query params for this route when naviating programmatically if set to true
9797
},
9898
home: {
9999
typeKeyMapping: {

src/useGenericNavQueryParams.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,21 @@ export default <
102102
// console.log("to: ",loadedByUser);
103103
};
104104

105-
if (initialOptions.adapter?.pushLocation) {
106-
initialOptions.adapter.pushLocation = new Proxy(
107-
initialOptions.adapter.pushLocation,
108-
{
109-
apply: (target, thisArg, argArray) => {
110-
// trigger here what you need
111-
initialize();
112-
return target.apply(thisArg, argArray);
113-
},
114-
}
115-
);
116-
}
117-
118-
if (initialOptions.adapter?.replaceLocation) {
119-
initialOptions.adapter.replaceLocation = new Proxy(
120-
initialOptions.adapter.replaceLocation,
121-
{
122-
apply: (target, thisArg, argArray) => {
123-
// trigger here what you need
124-
initialize();
125-
return target.apply(thisArg, argArray);
126-
},
127-
}
128-
);
129-
}
105+
window.history.pushState = new Proxy(window.history.pushState, {
106+
apply: (target, thisArg, argArray) => {
107+
// trigger here what you need
108+
initialize();
109+
return target.apply(thisArg, argArray);
110+
},
111+
});
112+
113+
window.history.replaceState = new Proxy(window.history.replaceState, {
114+
apply: (target, thisArg, argArray) => {
115+
// trigger here what you need
116+
initialize();
117+
return target.apply(thisArg, argArray);
118+
},
119+
});
130120

131121
const useNavQueryParams = <TInputRouteKey extends keyof T>(
132122
key: TInputRouteKey
@@ -356,10 +346,11 @@ export default <
356346
params.delete(key);
357347
}
358348
});
349+
const stringParams = params.toString();
359350
if (options.behaviour === "push") {
360-
adapter.pushLocation({ search: params.toString() });
351+
adapter.pushLocation({ search: stringParams });
361352
} else {
362-
adapter.replaceLocation({ search: params.toString() });
353+
adapter.replaceLocation({ search: stringParams });
363354
}
364355
},
365356
[query]

0 commit comments

Comments
 (0)