Skip to content

How to get current URL or pathname? #2773

Closed Answered by arno-fukuda
mrvectopus asked this question in Q&A
Discussion options

You must be logged in to vote
import { useRouter } from "next/router";

const Component = () => {
  const router = useRouter();
  const { pathname, asPath } = router;

  console.log("Pathname:", pathname);
  console.log("As Path:", asPath);

  return <div>hello world</div>;
};

export default Component;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mrvectopus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants