Render UI across server and client boundaries
Build a Next.js Server Component, Pass Props, and Show the Current Path
Pass posts between App Router Server Components and display the current pathname with a small usePathname Client Component.

In the App Router, you can keep a page and its posts list as Server Components. Pass the list as an ordinary prop; add a separate Client Component only for the pathname. That split matters because Next.js documents usePathname() as a Client Component hook, not as a general way for a Server Component to read the current request path.
Render a Server Component
Create app/posts/page.tsx in an App Router application:
import CurrentPath from './current-path'
type Post = {
id: number
title: string
}
const posts: Post[] = [
{ id: 1, title: 'Rendering a posts page' },
{ id: 2, title: 'Passing data to a list' },
]
function PostList({ posts }: { posts: Post[] }) {
return (
<ul>
{posts.map((post) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
)
}
export default function PostsPage() {
return (
<main>
<h1>Posts</h1>
<PostList posts={posts} />
<CurrentPath />
</main>
)
}
App Router pages are Server Components by default. There is no 'use client' directive in this file. Visiting /posts renders the two titles through PostList; the CurrentPath import supplies the small pathname display added below.
The array is deliberately local so the component handoff is easy to see. Server Components can also fetch data using fetch or a database/ORM when the list needs real records. That would change where posts comes from, not how PostList receives it.
Trace the posts prop
The page owns posts and passes it with <PostList posts={posts} />. PostList receives an object containing that prop, destructures the array, and maps each post to a list item. This is a page-to-component prop, not a server-to-client handoff: neither the page nor PostList starts a Client Component boundary.
The distinction is useful as a component tree grows. A 'use client' directive establishes a boundary for a module’s imports; importing a component into that client graph pulls its code into the client bundle. Here, the page imports and renders the client leaf, rather than moving the page or list into that graph. See the server and client boundary guide for how imports and props cross that boundary.
Show the current path in a client leaf
Add app/posts/current-path.tsx:
'use client'
import { useEffect, useState } from 'react'
import { usePathname } from 'next/navigation'
export default function CurrentPath() {
const pathname = usePathname()
const [visiblePath, setVisiblePath] = useState<string | null>(null)
useEffect(() => {
setVisiblePath(pathname)
}, [pathname])
return <p>Current path: {visiblePath ?? 'Loading path…'}</p>
}
Only this file has 'use client'. It reads usePathname() and, after mount, displays the returned value. At /posts, the visible line becomes Current path: /posts. The initial Loading path… text is intentional: it gives the pathname-dependent part a stable fallback before the client value is shown. The posts and their titles do not need to wait for that update.
The pathname examples in the Next.js API reference show that the hook returns the path without the query string. Visit /posts?sort=recent and the pathname display still becomes /posts; sort=recent is not part of the value this hook returns.
There is one reason not to render pathname-dependent text indiscriminately during the initial render. With prerendering and a rewrite or Proxy, the HTML can be generated for a source pathname while the browser URL has a different pathname. Next.js warns that this difference can cause a hydration mismatch and recommends isolating pathname-dependent UI behind a stable server fallback, then updating it after mount. That is why the example confines this behavior to CurrentPath instead of making the whole posts page depend on the browser pathname.




