UNPKG

@jk-core/hooks

Version:
20 lines (15 loc) 415 B
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;