To avoid breaking a user's flow through your app, when a user navigates to a Clerk sign up or sign in page via a link or button, Clerk will:
Persist the previous page's URL in a redirect_url query string
Navigate back to that page after the sign-up or sign-in is completed
For example, a user selecting a sign-in button on example.com/foo will navigate to example.com/sign-in?redirect_url=example.com/foo, then navigate back to example.com/foo upon completing the sign-in process.
However, you can customize this behavior to redirect users to a specific page by using the following methods:
You can define a fallback redirect URL in the case that there is no redirect_url in the path already. This is useful for users who navigate directly to the sign-in or sign-up page.
The following example shows how to define a fallback redirect URL for both sign-in and sign-up pages:
If you would like to override the redirect_url value and supply a custom redirect URL after sign-in or sign-up, you can use the following environment variables:
You can explicitly define the redirect paths after sign-up or sign-in by using the properties described in this section with Clerk's components. In general, it is recommended to use environment variables instead.
Warning
The afterSignIn, afterSignUp, and redirectUrl props are deprecated. If you're still using them, the props described in this section will override them.
The "fallback redirect URL" props will only be used if there is no redirect_url value. This can happen if the user has navigated directly to the sign up or sign in page.
fallbackRedirectUrl - Used by sign-in and sign-up related components.
signInFallbackRedirectUrl - Used on sign up components, such as <SignUp /> and <SignUpButton>.
signUpFallbackRedirectUrl - Used on sign in components, such as <SignIn /> and <SignInButton>.
The "force redirect URL" props will always redirect to the provided url after sign up or sign in, regardless of what page the user was on before, and will override the redirect_url value if present.
forceRedirectUrl - Used by sign-in and sign-up related components.
signInForceRedirectUrl - Used on sign up components, such as <SignUp /> and <SignUpButton>.
signUpForceRedirectUrl - Used on sign in components, such as <SignIn /> and <SignInButton>.
It is recommended to define both signInFallbackRedirectUrl and signUpFallbackRedirectUrl redirects in each button as some users may choose to sign up after attempting to sign-in, or sign in after attempting to sign-up.
It is recommended to define both signInFallbackRedirectUrl and signUpFallbackRedirectUrl redirects in each component as some users may choose to sign up instead after attempting to sign in.