useCurrentPath.tsx14 lines · main
| 1 | import { useRouter } from 'next/router' |
| 2 | |
| 3 | export 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 | } |