Skip to content

Commit

Permalink
docs(usePathname): add note about using usePathname with rewrites (ve…
Browse files Browse the repository at this point in the history
…rcel#69686)

## Why?

A `useState` + `useState` need to be used with `usePathname` when the
route is rewritten to. Adding this as a note to our documentation.

- x-ref:
vercel#69631 (review)
  • Loading branch information
samcx authored Sep 4, 2024
1 parent 38d8301 commit 12cbab2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions docs/02-app/02-api-reference/04-functions/use-pathname.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ For example, a Client Component with `usePathname` will be rendered into HTML on
> - Reading the current URL from a [Server Component](/docs/app/building-your-application/rendering/server-components) is not supported. This design is intentional to support layout state being preserved across page navigations.
> - Compatibility mode:
> - `usePathname` can return `null` when a [fallback route](/docs/pages/api-reference/functions/get-static-paths#fallback-true) is being rendered or when a `pages` directory page has been [automatically statically optimized](/docs/pages/building-your-application/rendering/automatic-static-optimization) by Next.js and the router is not ready.
> - When using `usePathname` with rewrites in [`next.config`](/docs/app/api-reference/next-config-js/rewrites) or [`Middleware`](/docs/app/building-your-application/routing/middleware), `useState` and `useEffect` must also be used in order to avoid hydration mismatch errors. See the [rewrites example](https://github.com/vercel/next.js/tree/canary/examples/rewrites) for more information.
> - Next.js will automatically update your types if it detects both an `app` and `pages` directory in your project.
## Parameters
Expand Down

0 comments on commit 12cbab2

Please sign in to comment.