Next.js · Junior · Question 22 of 75

How do you get the current path in a client component, e.g. to highlight the active link?

Explanation

usePathname() returns the path and updates on client-side navigation. Reading window during render breaks SSR and hydration. The pathname property on useRouter existed in the Pages Router; it isn't in next/navigation.

Further reading

Problem with a question

Next.js · Junior · question 22

Test yourself

Take the Next.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz