@jk-core/hooks
Version:
hooks for jk
20 lines (15 loc) • 415 B
text/typescript
const useHistory = () => {
const { history } = window;
const push = (path: string) => {
const currentUrl = new URL(window.location.href);
const newUrl = `${currentUrl.origin}${currentUrl.pathname}${currentUrl.search}${currentUrl.hash}/${path}`;
history.pushState({}, '', newUrl);
};
const back = () => {
history.back();
};
return {
push, back,
};
};
export default useHistory;