history#LocationDescriptorObject TypeScript Examples
The following examples show how to use
history#LocationDescriptorObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: historyExtended.ts From next-core with GNU General Public License v3.0 | 5 votes |
/**
* Override history for standalone micro apps.
*
* when `push` or `replace` to other apps, force page refresh.
*/
function standaloneHistoryOverridden(
browserHistory: History<PluginHistoryState>
): Pick<History<PluginHistoryState>, "push" | "replace"> {
const { push: originalPush, replace: originalReplace } = browserHistory;
function updateFactory(
method: "push" | "replace"
): History<PluginHistoryState>["push"] {
return function update(path, state?) {
let pathname: string;
const pathIsString = typeof path === "string";
if (pathIsString) {
pathname = parsePath(path).pathname;
} else {
pathname = path.pathname;
}
if (pathname === "" || _internalApiHasMatchedApp(pathname)) {
return (method === "push" ? originalPush : originalReplace)(
path as string,
state
);
}
// Going to outside apps.
return location[method === "push" ? "assign" : "replace"](
pathIsString
? getBasePath() + path.replace(/^\//, "")
: browserHistory.createHref(
path as LocationDescriptorObject<PluginHistoryState>
)
);
};
}
return {
push: updateFactory("push"),
replace: updateFactory("replace"),
};
}