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