Control access to your application pages based on authentication state.
The React SDK provides two wrapper components that make it incredibly easy to restrict access to certain parts of your application: <ProtectedRoute> and <GuestRoute>.
Use this component to wrap pages or layouts that only logged-in users should be able to see (e.g., Dashboards, User Settings).If a non-authenticated user attempts to view a protected route, they will be redirected to a path you specify.
import { ProtectedRoute } from '@urbackend/react';import Dashboard from './Dashboard';export default function ProtectedDashboard() { return ( <ProtectedRoute fallback={<div>Loading session...</div>} onRedirect={() => window.location.href = '/login'} > <Dashboard /> </ProtectedRoute> );}
Use this component to wrap pages that only non-logged-in users should see (e.g., Login pages, Signup pages).If an already-authenticated user attempts to view a guest route, they will be redirected away (usually to the dashboard).
What to render while the SDK is checking the authentication state (e.g. a spinner).
onRedirect
() => void
Yes
A callback fired when the user needs to be redirected. You can use your framework’s router (e.g. next/navigation or react-router-dom) inside this callback.
children
React.ReactNode
Yes
The components to render if the access condition is met.
Was this page helpful?
⌘I
{"docsConfig":{"theme":"luma","$schema":"https://mintlify.com/docs.json","name":"urBackend","colors":{"primary":"#53e5ae","light":"#347c64","dark":"#050706"},"logo":{"light":"https://media.brand.dev/4b788915-4c6f-48d5-b961-63e90c4e3c5e.png","dark":"https://media.brand.dev/4b788915-4c6f-48d5-b961-63e90c4e3c5e.png"},"favicon":"https://media.brand.dev/98c8a636-fed2-4095-a2d6-1ed768aca5dd.png","navbar":{"primary":{"type":"github","href":"https://github.com/geturbackend/urBackend"}},"footer":{"socials":{"github":"https://github.com/geturbackend/urBackend","discord":"https://discord.gg/CXJjvJkNWn"},"links":[{"header":"Backed by","items":[{"label":"MongoDB for Startups","href":"https://www.mongodb.com/startups"},{"label":"Mintlify OSS Program","href":"https://mintlify.com"}]}]},"seo":{"metatags":{"google-site-verification":"7EMPCEhVMV-pX3iYSiRSjNI6d5aLL2csbeDQySbOMV4"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"urbackend","hasAudioNarration":false,"actualSubdomain":"urbackend","customDomains":["docs.urbackend.in"],"gitSource":{"type":"github","owner":"geturbackend","repo":"urbackend","deployBranch":"main","contentDirectory":"mintlify/docs","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ab9be2bdbafdd017d6de1a4","collectionId":"591212d9-7afe-49b9-bfd4-456a52963a40","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ab9be2bdbafdd017d6de1a4"},"feedback":{"thumbs":true,"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6ab9be2bdbafdd017d6de1a4","clientVersion":"0.0.4044","searchFilterCounts":[{"language":"default","tag":"Docs","count":28},{"language":"default","tag":"API Reference","count":16},{"language":"default","tag":"Changelog","count":12},{"language":"default","tag":"Guides","count":8},{"language":"default","tag":"React SDK","count":7},{"language":"default","tag":"Authentication","count":6},{"language":"default","tag":"Database","count":6},{"language":"default","tag":"TypeScript SDK","count":6},{"language":"default","tag":"Core Concepts","count":3},{"language":"default","tag":"Overview","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":true,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true,"deflection":{"enabled":true,"email":"[email protected]"}},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[{"_id":"6a6e3216f17bcfd416de43b8","deploymentId":"69d6a09d908d1ac2f1464b1f","questionText":"Can I create a web app like x.com with urbackend?","status":"active","generatedBy":"manual","createdAt":"2026-08-01T17:51:18.893Z","updatedAt":"2026-08-01T17:51:18.893Z","__v":0}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"react-sdk/routing","slug":"/react-sdk/routing","pageMetadata":{"title":"Protected \u0026 Guest Routes","description":"Control access to your application pages based on authentication state.","href":"/react-sdk/routing"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Control access to your application pages based on authentication state.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The React SDK provides two wrapper components that make it incredibly easy to restrict access to certain parts of your application: `,_jsx(_components.code,{children:`\u003cProtectedRoute>`}),` and `,_jsx(_components.code,{children:`\u003cGuestRoute>`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`\u003cprotectedroute>`,children:_jsx(_components.code,{children:`\u003cProtectedRoute>`})}),`\n`,_jsxs(_components.p,{children:[`Use this component to wrap pages or layouts that only `,_jsx(_components.strong,{children:`logged-in users`}),` should be able to see (e.g., Dashboards, User Settings).`]}),`\n`,_jsx(_components.p,{children:`If a non-authenticated user attempts to view a protected route, they will be redirected to a path you specify.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`ProtectedRoute`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@urbackend/react'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Dashboard`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` './Dashboard'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` default`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ProtectedDashboard`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#4EC9B0`},children:`ProtectedRoute`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` fallback`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`div`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Loading session...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`\u003c/`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`div`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`>`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` onRedirect`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` window`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`location`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`href`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '/login'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` >`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#4EC9B0`},children:`Dashboard`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` />`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` \u003c/`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#4EC9B0`},children:`ProtectedRoute`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`>`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` );`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`\u003cguestroute>`,children:_jsx(_components.code,{children:`\u003cGuestRoute>`})}),`\n`,_jsxs(_components.p,{children:[`Use this component to wrap pages that only `,_jsx(_components.strong,{children:`non-logged-in users`}),` should see (e.g., Login pages, Signup pages).`]}),`\n`,_jsx(_components.p,{children:`If an already-authenticated user attempts to view a guest route, they will be redirected away (usually to the dashboard).`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`GuestRoute`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`UrAuth`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '@urbackend/react'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` default`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` LoginPage`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#4EC9B0`},children:`GuestRoute`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` fallback`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`div`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Loading...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`\u003c/`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`div`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`>`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` onRedirect`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` window`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`location`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`href`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '/dashboard'`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` >`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#4EC9B0`},children:`UrAuth`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` providers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'google'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'github'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` />`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:` \u003c/`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#4EC9B0`},children:`GuestRoute`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#808080`},children:`>`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` );`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`props-both-components`,children:`Props (Both Components)`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Prop`}),_jsx(_components.th,{children:`Type`}),_jsx(_components.th,{children:`Required`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`fallback`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`React.ReactNode`})}),_jsx(_components.td,{children:`Yes`}),_jsx(_components.td,{children:`What to render while the SDK is checking the authentication state (e.g. a spinner).`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`onRedirect`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`() => void`})}),_jsx(_components.td,{children:`Yes`}),_jsxs(_components.td,{children:[`A callback fired when the user needs to be redirected. You can use your framework’s router (e.g. `,_jsx(_components.code,{children:`next/navigation`}),` or `,_jsx(_components.code,{children:`react-router-dom`}),`) inside this callback.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`children`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`React.ReactNode`})}),_jsx(_components.td,{children:`Yes`}),_jsx(_components.td,{children:`The components to render if the access condition is met.`})]})]})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Protected \u0026 Guest Routes","description":"Control access to your application pages based on authentication state.","href":"/react-sdk/routing"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"\u003cProtectedRoute>","slug":"\u003cprotectedroute>","depth":2,"children":[]},{"title":"\u003cGuestRoute>","slug":"\u003cguestroute>","depth":2,"children":[]},{"title":"Props (Both Components)","slug":"props-both-components","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"urbackend","siteName":"urBackend","title":"Protected \u0026 Guest Routes - urBackend","relatedPagesConfig":{"enabled":true,"limit":4,"mode":"automatic"},"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-06-01T20:29:41.539Z","originalFileLocation":"react-sdk/routing.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Control access to your application pages based on authentication state.\">\u003cmeta data-mint-head name=\"application-name\" content=\"urBackend\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"https://media.brand.dev/98c8a636-fed2-4095-a2d6-1ed768aca5dd.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"https://media.brand.dev/98c8a636-fed2-4095-a2d6-1ed768aca5dd.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"https://media.brand.dev/98c8a636-fed2-4095-a2d6-1ed768aca5dd.png\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/png\" href=\"https://media.brand.dev/98c8a636-fed2-4095-a2d6-1ed768aca5dd.png\">\u003cmeta data-mint-head property=\"og:title\" content=\"Protected \u0026amp; Guest Routes - urBackend\">\u003cmeta data-mint-head property=\"og:description\" content=\"Control access to your application pages based on authentication state.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"urBackend\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.urbackend.in/react-sdk/routing\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://urbackend.mintlify.app/_mintlify/api/og/v2?division=React+SDK\u0026amp;title=Protected+%26+Guest+Routes\u0026amp;description=Control+access+to+your+application+pages+based+on+authentication+state.\u0026amp;theme=0fb3cfe0b41cdaff90c444da\u0026amp;signature=15810df082ef668a49f70b6416a1204e5eb85a521d201a9c02f7132b3e5198f7\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Protected \u0026amp; Guest Routes - urBackend\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Control access to your application pages based on authentication state.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://urbackend.mintlify.app/_mintlify/api/og/v2?division=React+SDK\u0026amp;title=Protected+%26+Guest+Routes\u0026amp;description=Control+access+to+your+application+pages+based+on+authentication+state.\u0026amp;theme=0fb3cfe0b41cdaff90c444da\u0026amp;signature=15810df082ef668a49f70b6416a1204e5eb85a521d201a9c02f7132b3e5198f7\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"https://mintlify.s3.us-west-1.amazonaws.com/urbackend/_generated/favicon/browserconfig.xml?v=3\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"urBackend\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#53e5ae\">\u003cmeta data-mint-head name=\"google-site-verification\" content=\"7EMPCEhVMV-pX3iYSiRSjNI6d5aLL2csbeDQySbOMV4\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.urbackend.in/react-sdk/routing\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/react-sdk/routing.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.urbackend.in/#organization\",\"name\":\"urBackend\",\"url\":\"https://docs.urbackend.in\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://media.brand.dev/4b788915-4c6f-48d5-b961-63e90c4e3c5e.png\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.urbackend.in#website\",\"name\":\"urBackend\",\"url\":\"https://docs.urbackend.in\",\"publisher\":{\"@id\":\"https://docs.urbackend.in/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.urbackend.in/react-sdk/routing#webpage\",\"url\":\"https://docs.urbackend.in/react-sdk/routing\",\"name\":\"Protected \u0026 Guest Routes\",\"description\":\"Control access to your application pages based on authentication state.\",\"dateModified\":\"2026-06-01T20:29:41.539Z\",\"isPartOf\":{\"@id\":\"https://docs.urbackend.in#website\"},\"breadcrumb\":{\"@id\":\"https://docs.urbackend.in/react-sdk/routing#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.urbackend.in/react-sdk/routing#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"React SDK\",\"item\":\"https://docs.urbackend.in/react-sdk/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Protected \u0026 Guest Routes\",\"item\":\"https://docs.urbackend.in/react-sdk/routing\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.urbackend.in/react-sdk/routing#article\",\"headline\":\"Protected \u0026 Guest Routes\",\"name\":\"Protected \u0026 Guest Routes\",\"description\":\"Control access to your application pages based on authentication state.\",\"url\":\"https://docs.urbackend.in/react-sdk/routing\",\"mainEntityOfPage\":{\"@id\":\"https://docs.urbackend.in/react-sdk/routing#webpage\"},\"dateModified\":\"2026-06-01T20:29:41.539Z\",\"publisher\":{\"@id\":\"https://docs.urbackend.in/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.urbackend.in#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"urBackend\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"urBackend","nav":{"global":null,"tabs":[{"tab":"Docs","groups":[{"group":"Get Started","pages":[{"title":"Introduction","icon":"face-smile-upside-down","href":"/introduction"},{"title":"Quick Start","href":"/quickstart"}]},{"group":"Core Concepts","pages":[{"title":"API Keys","href":"/concepts/api-keys"},{"title":"Collections \u0026 Schemas","href":"/concepts/collections-schemas"},{"title":"Row-Level Security","href":"/concepts/row-level-security"}]},{"group":"Guides","pages":[{"title":"Authentication","href":"/guides/authentication"},{"title":"Social Auth","href":"/guides/social-auth"},{"title":"Mail Platform","href":"/guides/mail-platform"},{"title":"Database","href":"/guides/database"},{"title":"Storage","href":"/guides/storage"},{"title":"Webhooks","href":"/guides/webhooks"},{"title":"Audit log","href":"/guides/audit-log"},{"title":"BYOK for AI","href":"/guides/ai-byok"},{"title":"AI Collection Creator","href":"/guides/ai-collection-creator"}]},{"group":"TypeScript SDK","pages":[{"title":"SDK Overview","href":"/sdk/overview"},{"title":"Auth","href":"/sdk/auth"},{"title":"Database","href":"/sdk/database"},{"title":"Storage","href":"/sdk/storage"},{"title":"Schema","href":"/sdk/schema"},{"title":"Mail","href":"/sdk/mail"}]},{"group":"React SDK","pages":[{"title":"React SDK Overview","href":"/react-sdk/overview"},{"title":"\u003cUrProvider>","href":"/react-sdk/ur-provider"},{"title":"\u003cUrAuth>","href":"/react-sdk/ur-auth"},{"title":"\u003cUrUserButton>","description":"A drop-in profile button with a dropdown menu for authenticated users.","href":"/react-sdk/ur-user-button"},{"title":"Protected \u0026 Guest Routes","href":"/react-sdk/routing"},{"title":"React Hooks","description":"Interact with the urBackend SDK natively using React hooks.","href":"/react-sdk/hooks"},{"title":"Full Integration Example","href":"/react-sdk/integration"}]},{"group":"Security \u0026 Limits","pages":[{"title":"Security","href":"/security"},{"title":"Limits \u0026 Quotas","href":"/limits-and-quotas"}]}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog/september-2026"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/overview"}]},{"tab":"CLI Reference","pages":[{"title":"CLI Reference","href":"/cli/overview"}]}]},"basePath":"","title":"Protected \u0026 Guest Routes - urBackend","buildId":"dpl_DeHjVRGfFnhYQwHnfC2pjeXXv8h9","deploymentId":"dpl_DeHjVRGfFnhYQwHnfC2pjeXXv8h9","dynamics":[],"chunks":[]}