useCurrentPath.tsx 265 B

1234567891011121314
  1. import { useRouter } from 'next/router'
  2. export const useCurrentPath = () => {
  3. const router = useRouter()
  4. if (!router.isReady) {
  5. return ''
  6. }
  7. const pathWithQuery = router.asPath
  8. const currentPath = pathWithQuery.split('?')[0]
  9. return currentPath
  10. }