Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

Add custom pages and links to the <UserProfile /> component

The <UserProfile /> component supports the addition of custom pages and use of external links in the navigation sidebar.

There are two ways to render the <UserProfile /> component:

  • As a modal
  • As a dedicated page

Both can be accessed when the user selects the <UserButton />, and then selects the Manage account option.

This guide includes examples for both use cases. You can select one of the following two tabs on the code examples to see the implementation for your preferred use case:

  • <UserButton /> tab: By default, the <UserButton /> sets userProfileMode='modal'. If you are using the default settings, then you should select this tab.
  • Dedicated page tab: If you do not want the <UserProfile /> to open as a modal, then you should select this tab. For these examples, you need to set userProfileMode='navigation' and userProfileUrl='/user-profile' on the <UserButton /> component.

For the sake of this guide, examples are written for Next.js App Router, but they are supported by any React meta framework, such as Remix or Gatsby.

Add a custom page to <UserProfile />

Custom pages can be rendered inside the <UserProfile /> component and provide a way to incorporate app-specific settings or additional functionality.

To add a custom page to the <UserProfile /> component, use the <UserButton.UserProfilePage /> component or the <UserProfile.Page /> component, depending on your use case.

Props

<UserButton.UserProfilePage /> and <UserProfile.Page /> accept the following props, all of which are required:

NameTypeDescription
labelstringThe name that will be displayed in the navigation sidebar for the custom page.
labelIconReact.ReactElementAn icon displayed next to the label in the navigation sidebar.
urlstringThe path segment that will be used to navigate to the custom page. (e.g. if the <UserProfile /> component is rendered at /user, then the custom page will be accessed at /user/{url} when using path routing)
childrenReact.ReactElementThe components to be rendered as content inside the custom page.

Example

The following example demonstrates two ways that you can render content in the <UserButton.UserProfilePage /> or <UserProfile.Page /> component: as a component or as a direct child.

/app/components/Header.tsx
"use client"; import { UserButton } from "@clerk/nextjs"; const DotIcon = () => { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor" > <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" /> </svg> ) } const CustomPage = () => { return ( <div> <h1>Custom Profile Page</h1> <p>This is the custom profile page</p> </div> ); }; const Header = () => ( <header> <UserButton afterSignOutUrl='/'> {/* You can pass the content as a component */} <UserButton.UserProfilePage label="Custom Page" url="custom" labelIcon={<DotIcon />} > <CustomPage /> </UserButton.UserProfilePage> {/* You can also pass the content as direct children */} <UserButton.UserProfilePage label="Terms" labelIcon={<DotIcon />} url="terms" > <div> <h1>Custom Terms Page</h1> <p>This is the custom terms page</p> </div> </UserButton.UserProfilePage> </UserButton> </header> ); export default Header;
/app/user-profile/[[...user-profile]]/page.tsx
"use client"; import { UserProfile } from '@clerk/nextjs'; const DotIcon = () => { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor" > <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" /> </svg> ) } const CustomPage = () => { return ( <div> <h1>Custom Profile Page</h1> <p>This is the custom profile page</p> </div> ); }; const UserProfilePage = () => ( <UserProfile path="/user-profile" routing="path"> {/* You can pass the content as a component */} <UserProfile.Page label="Custom Page" labelIcon={<DotIcon />} url="custom-page" > <CustomPage /> </UserProfile.Page> {/* You can also pass the content as direct children */} <UserProfile.Page label="Terms" labelIcon={<DotIcon />} url="terms" > <div> <h1>Custom Terms Page</h1> <p>This is the custom terms page</p> </div> </UserProfile.Page> </UserProfile> ); export default UserProfilePage;

You can add external links to the <UserProfile /> navigation sidebar using the <UserButton.UserProfileLink /> component or the <UserProfile.Link /> component, depending on your use case.

Props

<UserButton.UserProfileLink /> and <UserProfile.Link /> accept the following props, all of which are required:

NameTypeDescription
labelstringThe name that will be displayed in the navigation sidebar for the link.
labelIconReact.ReactElementAn icon displayed next to the label in the navigation sidebar.
urlstringThe absolute or relative url to navigate to

Example

The following example adds a link to the homepage in the navigation sidebar of the <UserProfile /> component.

/app/components/Header.tsx
"use client"; import { UserButton } from "@clerk/nextjs"; const DotIcon = () => { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor" > <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" /> </svg> ) } const Header = () => ( <header> <UserButton afterSignOutUrl='/'> <UserButton.UserProfileLink label="Homepage" url="/" labelIcon={<DotIcon />} /> </UserButton> </header> ); export default Header;
/app/user-profile/[[...user-profile]]/page.tsx
"use client"; import { UserProfile } from "@clerk/nextjs"; const DotIcon = () => { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor" > <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" /> </svg> ) } const UserProfilePage = () => ( <UserProfile path="/user-profile" routing="path"> <UserProfile.Link label="Homepage" labelIcon={<DotIcon />} url="/" /> </UserProfile> ); export default UserProfilePage;

Reorder default routes

If you want to reorder the default routes, Account and Security, set the label prop to 'account' or 'security'. This will target the existing default page and allow you to rearrange it.

Note that when reordering default routes, the first item in the navigation sidebar cannot be a <UserButton.UserProfileLink /> or <UserProfile.Link /> component.

/app/components/Header.tsx
"use client"; import { UserButton } from "@clerk/nextjs"; const DotIcon = () => { return ( <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor" > <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" /> </svg> ) } const CustomPage = () => { return ( <div> <h1>Custom Profile Page</h1> <p>This is the custom profile page</p> </div> ); }; const Header = () => ( <header> <UserButton afterSignOutUrl='/'> <UserButton.UserProfilePage label="Custom Page" url="custom" labelIcon={<DotIcon />} > <CustomPage /> </UserButton.UserProfilePage> <UserButton.UserProfileLink label="Homepage" url="/" labelIcon={<DotIcon />} /> <UserButton.UserProfilePage label="account" /> <UserButton.UserProfilePage label="security" /> </UserButton> </header> ); export default Header;

With the above example, the <UserProfile /> navigation sidebar will be in the following order:

  1. Custom Page
  2. Homepage
  3. Account
  4. Security

Last updated on March 8, 2024

What did you think of this content?

Clerk © 2024