Add custom pages and links to the <OrganizationProfile /> component
The <OrganizationProfile /> component supports the addition of custom pages and external links to the component's sidenav. It only accepts the following components as children:
<OrganizationSwitcher.OrganizationProfilePage />or<OrganizationProfile.Page />to add a custom page.<OrganizationSwitcher.OrganizationProfileLink />or<OrganizationProfile.Link />to add a custom link.
You can also reorder default routes.
Before you start
Before you start, it's important to understand how the <OrganizationProfile /> can be accessed:
- As a modal: When a user selects the <OrganizationSwitcher /> component and then selects the Manage Organization option, the
<OrganizationProfile />will open as a modal by default. - As a dedicated page: You can embed the
<OrganizationProfile />component itself in a dedicated page.
This guide includes examples for both use cases. On the code examples, you can select one of the following two tabs to see the implementation for your preferred use case:
<OrganizationSwitcher />tab: By default, the<OrganizationSwitcher />setsorganizationProfileMode='modal'. If you are using the default settings, then you should select this tab.Dedicated pagetab: If you do not want the<OrganizationProfile />to open as a modal, then you should select this tab. For these examples, on the<OrganizationSwitcher />component, you need to setorganizationProfileMode='navigation'andorganizationProfileUrl='/organization-profile'.
Add a custom page
To add a custom page to the <OrganizationProfile /> component, you will need to use one of the following components, depending on the use case mentioned in the Before you start section.
Props
<OrganizationSwitcher.OrganizationProfilePage /> and <OrganizationProfile.Page /> accept the following props, all of which are required:
- Name
label- Type
string- Description
The name that will be displayed in the navigation sidenav for the custom page.
- Name
labelIcon- Type
React.ReactElement- Description
An icon displayed next to the label in the navigation sidenav.
- Name
url- Type
string- Description
The path segment that will be used to navigate to the custom page. For example, if the
<OrganizationProfile />component is rendered at/organization, then the custom page will be accessed at/organization/{url}when using path routing.
- Name
children- Type
React.ReactElement- Description
The content to be rendered inside the custom page.
To add custom pages to the <OrganizationProfile /> component using the JavaScript SDK, pass the customPages property to the mountOrganizationProfile() method, as shown in the following example:
import { Clerk } from '@clerk/clerk-js'
const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
const clerk = new Clerk(pubKey)
await clerk.load()
document.getElementById('app').innerHTML = `
<div id="organization-profile"></div>
`
const orgProfileDiv = document.getElementById('organization-profile')
clerk.mountOrganizationProfile(orgProfileDiv, {
customPages: [
{
url: 'custom-page',
label: 'Custom Page',
mountIcon: (el) => {
el.innerHTML = '👋'
},
unmountIcon: (el) => {
el.innerHTML = ''
},
mount: (el) => {
el.innerHTML = `
<h1><b>Custom Page</b></h1>
<p>This is the content of the custom page.</p>
`
},
unmount: (el) => {
el.innerHTML = ''
},
},
{
url: '/other-page',
label: 'Other Page',
mountIcon: (el) => {
el.innerHTML = '🌐'
},
unmountIcon: (el) => {
el.innerHTML = ''
},
},
],
})Reorder default routes
The <OrganizationProfile /> component includes two default menu items: Members and General, in that order. You can reorder these default items by setting the label prop to 'members' or 'general'. This will target the existing default item and allow you to rearrange it.
Note that when reordering default routes, the first item in the navigation sidenav cannot be a custom link.
Example
The following example adds a custom page as the first item in the sidenav, followed by a custom link to the homepage, and then the default Members and General pages.
import { Clerk } from '@clerk/clerk-js'
const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
const clerk = new Clerk(pubKey)
await clerk.load()
document.getElementById('app').innerHTML = `
<div id="organization-profile"></div>
`
const orgProfileDiv = document.getElementById('organization-profile')
clerk.mountOrganizationProfile(orgProfileDiv, {
customPages: [
{
url: 'custom-page',
label: 'Custom Page',
mountIcon: (el) => {
el.innerHTML = '👋'
},
unmountIcon: (el) => {
el.innerHTML = ''
},
mount: (el) => {
el.innerHTML = `
<h1><b>Custom Page</b></h1>
<p>This is the content of the custom page.</p>
`
},
unmount: (el) => {
el.innerHTML = ''
},
},
{
label: 'members',
},
{
label: 'general',
},
],
})Feedback
Last updated on