@lifi/widget
Version:
LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.
36 lines (31 loc) • 904 B
text/typescript
import { useCallback } from 'react'
import { useNavigate } from 'react-router-dom'
export const useNavigateBack = () => {
const navigate = useNavigate()
const navigateBack = useCallback(
(toPathname?: string) => {
// TODO: find a better router with nested memory routers support
// https://github.com/remix-run/react-router/pull/9112
// https://github.com/remix-run/react-router/discussions/9601
//
// if (window.history.length > 2) {
// navigate(-1)
// } else {
// navigate(
// window.location.pathname.substring(
// 0,
// window.location.pathname.lastIndexOf('/'),
// ) || '/',
// { replace: true },
// );
// }
if (toPathname) {
navigate(toPathname)
} else {
navigate(-1)
}
},
[navigate]
)
return { navigateBack, navigate }
}