Build your own sign-up page for your React app with Clerk
By default, the <SignIn /> component handles signing in and signing up, but if you'd like to have a dedicated sign-up page, this guide shows you how to use the <SignUp /> component to build a custom sign-up page.
This example assumes you have already set up the sign-in page by following the custom sign-in-or-up page guide
Build a sign-up page
The following example demonstrates how to render the <SignUp /> component on a dedicated sign-up page.
Create a src/sign-up.tsx file and add the following code:
import { SignUp } from '@clerk/react'
export default function SignUpPage() {
return <SignUp />
}Update your src/App.tsx file to add the SignUpPage() component and handle the /sign-up route.
import { Show, SignInButton, SignUpButton, UserButton, SignIn, SignUp } from '@clerk/react'
function SignInPage() {
return <SignIn path="/sign-in" />
}
function SignUpPage() {
return <SignUp path="/sign-up" />
}
export default function App() {
const path = window.location.pathname
if (path === '/sign-in' || path.startsWith('/sign-in/')) {
return (
<div>
<SignInPage />
</div>
)
}
if (path === '/sign-up' || path.startsWith('/sign-up/')) {
return (
<div>
<SignUpPage />
</div>
)
}
return (
<header>
<Show when="signed-out">
<SignInButton />
<SignUpButton />
</Show>
<Show when="signed-in">
<UserButton />
</Show>
</header>
)
}Update your src/main.tsx to import the sign-up page, add a route for it, and add the signUpUrl prop to your <ClerkProvider>.
- Set
signUpUrlto tell Clerk where the<SignUp />component is being hosted. - Set
signUpFallbackRedirectUrlas a fallback URL in case users visit the/sign-uproute directly. - Set
signInFallbackRedirectUrlas a fallback URL in case users select the 'Already have an account? Sign in' link at the bottom of the component.
Learn more about these props and how to customize Clerk's redirect behavior in the dedicated guide.
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter, Routes, Route, useNavigate } from 'react-router'
import { ClerkProvider } from '@clerk/react'
import './index.css'
import SignInPage from './sign-in.tsx'
import SignUpPage from './sign-up.tsx'
import App from './App.tsx'
function RootLayout() {
const navigate = useNavigate()
return (
<ClerkProvider
routerPush={(to) => navigate(to)}
routerReplace={(to) => navigate(to, { replace: true })}
signInUrl="/sign-in"
signUpUrl="/sign-up"
signInFallbackRedirectUrl="/"
signUpFallbackRedirectUrl="/"
>
<Routes>
<Route path="/" element={<App />} />
{/* Must be a splat route (catch-all) route to handle nested paths */}
<Route path="/sign-in/*" element={<SignInPage />} />
<Route path="/sign-up/*" element={<SignUpPage />} />
</Routes>
</ClerkProvider>
)
}
createRoot(document.getElementById('root')!).render(
<StrictMode>
<BrowserRouter>
<RootLayout />
</BrowserRouter>
</StrictMode>,
)Update your <ClerkProvider> to add the signUpUrl prop alongside the existing props.
- Set
signUpUrlto tell Clerk where the<SignUp />component is being hosted. - Set
signUpFallbackRedirectUrlas a fallback URL in case users visit the/sign-uproute directly. - Set
signInFallbackRedirectUrlas a fallback URL in case users select the 'Already have an account? Sign in' link at the bottom of the component.
Learn more about these props and how to customize Clerk's redirect behavior in the dedicated guide.
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { ClerkProvider } from '@clerk/react'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ClerkProvider
signInUrl="/sign-in"
signUpUrl="/sign-up"
signInFallbackRedirectUrl="/"
signUpFallbackRedirectUrl="/"
>
<App />
</ClerkProvider>
</React.StrictMode>,
)Visit your new page
Run your project with the following command:
npm run devpnpm run devyarn devbun run devVisit your new custom page locally at localhost:5173/sign-up.
Next steps
Learn more about Clerk components, how to use them to create custom pages, and how to use Clerk's client-side helpers using the following guides.
Protect content and read user data
Learn how to use Clerk's hooks to protect content and read user data in your React app.
Prebuilt components
Learn how to quickly add authentication to your app using Clerk's suite of components.
Customization & localization
Learn how to customize and localize the Clerk components.
Clerk React SDK Reference
Learn about the Clerk React SDK and how to integrate it into your app.
Feedback
Last updated on