Use defineAppRoutes() to declare page addresses, components, navigation and access rules. To run the example app and prepare an account, see environment and startup.
Register pages
Declare routes and connect them to the runtime
Declare pages in client/pages/projects/routes.ts and collect them for the runtime in client/routes.ts. This excerpt keeps the project list declaration and omits its outer group and child routes:
// client/pages/projects/routes.ts (excerpt: outer group and child routes omitted)
import { FolderKanban } from 'lucide-react';
import { defineAppRoutes } from '@nocobase/app-client/plugins';
export const projectRoutes = defineAppRoutes([
{
name: 'projects',
path: '/projects',
auth: 'required',
authz: { resource: { type: 'page', id: 'projects' }, action: 'access' },
navigation: { title: 'demo.projects', icon: FolderKanban },
componentLoader: () => import('./index.js'),
},
]);// client/routes.ts
import { projectRoutes, appendedRoutes } from './pages/projects/routes.js';
// Retain the template appRoutes and systemSettingsRoutes.
export default [appRoutes, appendedRoutes, projectRoutes, systemSettingsRoutes];defineAppRoutes() takes a readonly array of definitions and returns a frozen { parent: 'app', routes: [...] } contribution. It does not load components immediately. Runtime routes accepts one contribution or a flat array of contributions; the template already imports this file in client/runtime.ts. Calling the function in an unused file does not register anything. Do not mutate the returned object or pass an array of contributions back into defineAppRoutes().
Open Project list from the example home page to see the registered page and its navigation entry. Its authz requires project access, which the example administrator has.

Load page components
componentLoader must return Promise<{ default: Component }>. The project list uses import('./index.js') to load the default export from index.tsx. The page uses the template's reusable PageContainer, PageHeader and DataTable components.
A module can also provide a named export. The standalone project route uses ProjectPage from workspace.tsx, adapting it to the required structure:
// client/pages/projects/routes.ts
componentLoader: () =>
import('./workspace.js').then((module) => ({ default: module.ProjectPage })),Select Open as a full page in the project drawer to see this named export at /project-pages/p100.
A loader receives no route parameters and is not a data fetching function. Read parameters inside the component, and see data requests and state management for fetching data. Do not return a JSX element directly from the loader.

Path parameters and page navigation
Static paths and dynamic parameters
A route's path is relative to the application. With the default /main deployment prefix, /projects appears as /main/projects in the browser. Keep /main out of route declarations.
The example routes use both static paths and dynamic parameters:
| Application path | Purpose |
|---|---|
/projects | Project list |
/projects/new | Draft form; static new takes precedence over :projectId |
/projects/:projectId | Open details by project ID |
/projects/:projectId/tasks/:taskId | Identify both a project and a task |
detail.tsx uses React Router's useParams() to read a parameter and find its demonstration record:
import { useParams } from 'react-router';
import { projects } from './data.js';
// Inside the ProjectDetail component
const { projectId } = useParams();
const project = projects.find((item) => item.id === projectId);Parameter values are strings, and children can read parent parameters. /projects/p100 resolves Harbor launch; /projects/missing displays a missing-record message. The template handles route matching; the page implements record lookup and missing-record handling.

Query parameters and navigation
Enter Harbor in Search projects. The address becomes /projects?q=Harbor; selecting Harbor launch opens /projects/p100?q=Harbor. index.tsx updates the query through React Router's useSearchParams(). This excerpt omits table configuration and unrelated component props:
// client/pages/projects/index.tsx
const location = useLocation();
const [search, setSearch] = useSearchParams();
const query = search.get('q') ?? '';
<Input
value={query}
onChange={(event) => {
const next = new URLSearchParams(search);
if (event.target.value) next.set('q', event.target.value);
else next.delete('q');
setSearch(next, { replace: true });
}}
/>
// Inside the DataTable name cell
<RecordLink to={{ pathname: row.original.id, search: location.search }}>
{row.original.name}
</RecordLink>RecordLink wraps React Router's Link. Relative p100 extends the list path. Pass the query explicitly: nesting does not preserve it automatically. The list filters its fixtures by q; setSearch(next, { replace: true }) avoids creating a history entry for each edit.

Nested routes and page presentation
Standalone pages and child routes
A page can be registered independently or as another page's child. The difference is whether it renders through the parent's content outlet:
| Declaration | Example address | Content location |
|---|---|---|
| Sibling of the list | /project-pages/p100 | Standalone page, outside the list outlet |
Inside the list's children | /projects/p100 | The list's Outlet |
The standalone page in routes.ts is a sibling of the list and reuses ProjectPage:
// A sibling route of projects
{
name: 'projectStandalone',
path: '/project-pages/:projectId',
authz: { resource: { type: 'page', id: 'projects' }, action: 'access' },
breadcrumb: { title: 'demo.projectPage' },
componentLoader: () =>
import('./workspace.js').then((module) => ({ default: module.ProjectPage })),
}See the screenshot under Load page components: the standalone page reuses the named export without the list outlet.
Select Open as a full page in the drawer to open this independent page. To host details within the list instead, declare the hierarchy through children:
// Children of the projects page (excerpt)
children: [
{
name: 'projectDetail',
path: ':projectId',
componentLoader: () => import('./detail.js'),
children: [
{
name: 'projectTask',
path: 'tasks/:taskId',
componentLoader: () => import('./task.js'),
},
],
},
],The parent must render React Router's Outlet. This list also passes its query through context; the detail component reads it with useOutletContext():
// client/pages/projects/index.tsx
const context = useMemo(() => ({ listSearch: location.search }), [location.search]);
<Outlet context={context} />children defines the hierarchy, and Outlet supplies a rendering location. The page component chooses whether to embed content, cover the parent, or display a drawer or dialog. A child route declaration does not create those presentations automatically.
Embedded child pages and default tabs
Open Project reports. /reports redirects to /reports/summary; Owners switches to /reports/owners. reports/index.tsx redirects only when the address exactly matches the parent:
// client/pages/reports/index.tsx (excerpt)
const location = useLocation();
const parent = useResolvedPath('.');
if (matchPath({ path: parent.pathname, end: true }, location.pathname)) {
return <Navigate replace to={{ pathname: 'summary', search: location.search }} />;
}
// These elements go in the navigation and content returned by the component.
<NavLink to={{ pathname: 'owners', search: location.search }}>
{t('demo.owners')}
</NavLink>
<Outlet />Navigate replace avoids adding a redundant parent entry to history. end: true prevents a direct visit to Owners from being redirected to Summary. NavLink identifies the active tab; Outlet renders its content. Both children inherit the report page's authorization.


Child pages that cover parent content
Select Open workspace in the drawer to open /projects/workspace/p100?q=Harbor. workspace.tsx uses the template's RouteChildPage to cover the parent content while keeping the application navigation available:
// Another child of the projects page
{
name: 'projectWorkspace',
path: 'workspace/:projectId',
breadcrumb: { title: 'demo.workspace' },
componentLoader: () => import('./workspace.js'),
}
// client/pages/projects/workspace.tsx
export default function ProjectWorkspace() {
return <RouteChildPage><ProjectPage /></RouteChildPage>;
}The workspace still renders through the list's outlet. Its heading and breadcrumb use the project name; see static and dynamic breadcrumbs for that configuration.

Route drawers and nested dialogs
detail.tsx uses the template's RouteDrawer to display the project. This excerpt omits record lookup, missing-record handling and other buttons:
// client/pages/projects/detail.tsx (excerpt)
const { projectId } = useParams();
const { listSearch } = useOutletContext<{ listSearch: string }>();
<RouteDrawer title={project.name} footer={<CloseButton />}>
<RecordLink to={{ pathname: `tasks/${task.id}`, search: listSearch }}>
{task.name}
</RecordLink>
<Outlet />
</RouteDrawer>Selecting a project opens the drawer over the filtered list. Opening or refreshing /projects/p100?q=Harbor restores this page state.

Select Prepare launch checklist to open /projects/p100/tasks/t200?q=Harbor. task.tsx reads its own parameter and the parent parameter, then renders RouteDialog:
// client/pages/projects/task.tsx (excerpt)
const { projectId, taskId } = useParams();
<RouteDialog title={task.name} footer={<CloseTask />}>
<p>{t('demo.taskPath', { projectId, taskId })}</p>
</RouteDialog>Keep the second Outlet inside the detail drawer: it renders the task dialog. Back to project closes only the inner dialog. Closing the drawer then returns to the list.

View detail source · View task source
Return navigation and leave confirmation
Return to the parent and preserve query parameters
Try the draft dialog from /projects?q=Harbor: New draft opens /projects/new?q=Harbor. Enter a name and select Preview draft, then Finish preview to return to /projects?q=Harbor with the search preserved. These actions do not create a project.


The complete form gets close() from useRouteOverlay() inside a component rendered in the dialog:
// Call this inside a button component rendered within RouteDialog.
const { close } = useRouteOverlay();
<Button onClick={() => {
onFinish(); // Clear the draft dirty flag in this example.
void close();
}}>
{t('demo.finishPreview')}
</Button>close() returns to the matched parent route and preserves the query, avoiding assumptions about the last URL segment. The close icon, Escape and backdrop use the same close flow. For ordinary programmatic navigation, see React Router's useNavigate().
Confirm before leaving unsaved changes
After entering a name, select Close. Discard this unsaved draft? lets you keep editing or discard and return to the list:
// client/pages/projects/new.tsx (excerpt)
const dirtyRef = useRef(false);
const pendingDecisionRef = useRef<{
promise: Promise<boolean>;
resolve: (allowed: boolean) => void;
} | null>(null);
const [confirmOpen, setConfirmOpen] = useState(false);
const canLeave = useCallback((): boolean | Promise<boolean> => {
if (!dirtyRef.current) return true;
if (!pendingDecisionRef.current) {
let resolve!: (allowed: boolean) => void;
const promise = new Promise<boolean>((done) => { resolve = done; });
pendingDecisionRef.current = { promise, resolve };
setConfirmOpen(true);
}
return pendingDecisionRef.current.promise;
}, []);
useNavigationGuard(canLeave);
// RouteDialog also receives canLeave as beforeClose.
// AlertDialog buttons call decide(false) or decide(true).
const decide = (allowed: boolean) => {
setConfirmOpen(false);
if (allowed) dirtyRef.current = false;
pendingDecisionRef.current?.resolve(allowed);
pendingDecisionRef.current = null;
};
useEffect(() => () => pendingDecisionRef.current?.resolve(false), []);The same asynchronous decision is passed to RouteDialog.beforeClose and useNavigationGuard(). They cover overlay close and application navigation, including browser history traversal. The default template places NavigationGuardProvider outside the routes. Returning false blocks departure, true allows it, and a Promise waits for the choice.
While confirmation is open, overlapping requests share one Promise so a single choice settles every waiter without overwriting a callback. Resolve any pending request with false on unmount. Clear the dirty flag when allowing departure to avoid a second confirmation during the close navigation.
The full implementation also handles beforeunload for reloads and leaving the site. The browser supplies that native confirmation text; application navigation guards do not replace it.

Navigation menus and breadcrumbs
Menu configuration, groups and selection
A route's navigation creates its menu entry. A pathless Projects group organizes the list; omitting the complete page declaration, its group looks like this:
{
name: 'business',
navigation: { title: 'demo.business', order: 10 },
children: [
// Place the projects page declaration here.
],
}Reports uses an Insights group with the /reports prefix. A group has no component and organizes its children without needing its own Outlet:
{
name: 'reportsGroup',
path: '/reports',
navigation: { title: 'demo.insights', order: 20 },
children: [
{
name: 'reports',
path: '/',
authz: 'skip',
navigation: { title: 'demo.reports', icon: ChartColumn },
componentLoader: () => import('../reports/index.js'),
children: [
{ name: 'reportSummary', path: 'summary',
componentLoader: () => import('../reports/summary.js') },
{ name: 'reportOwners', path: 'owners',
componentLoader: () => import('../reports/owners.js') },
],
},
],
}The child's path: '/' lands at the group address /reports. The group itself does not claim a page address. Only navigation creates a menu entry: details and tasks remain accessible through record links without adding menus.
title is text or a translation key; icon is a React component such as a Lucide icon, not a string or JSX element. order is a finite number, defaults to 0, and sorts siblings in ascending order. Group headings do not show icons. A nested task keeps Project list selected. Authorization hides inaccessible pages and empty groups.

Static and dynamic breadcrumbs
breadcrumb and usePageBreadcrumb() connect route metadata and page content to the application template breadcrumb.
breadcrumb: { title: 'demo.workspace' } supplies a static route title. Once the project is available, usePageBreadcrumb() replaces it with the project name:
// client/pages/projects/workspace.tsx (excerpt)
usePageBreadcrumb(
project
? [
{
label: t('demo.projects'),
to: { pathname: '/projects', search: location.search },
},
{ label: project.name },
]
: undefined,
);label is display text and to is an optional destination. The final item is not a link. Pass undefined or null to use the default route breadcrumb. The innermost active declaration takes precedence; unmounting restores the outer declaration.
The screenshot under Child pages that cover parent content shows Project list → Harbor launch. Selecting Project list returns with q=Harbor. The template remembers queries from visited ancestors in the current hierarchy, but a deep link or reload may lack that history. Specify to explicitly when returning with a query must work in those cases.
Authentication and page permissions
Sign-in requirements and page layouts
The route definitions demonstrate all three auth values in separate route trees:
// Three independent routes, not a parent/child tree.
{ name: 'projects', path: '/projects', auth: 'required', /* ... */ }
{ name: 'welcome', path: '/welcome', auth: 'guest', authz: 'skip', /* ... */ }
{ name: 'publicProjects', path: '/public-projects', auth: 'optional', authz: 'skip', /* ... */ }| Usage | Action | Default template behavior |
|---|---|---|
required | Open /projects in a signed-out window | Redirects to /login; signed-in pages use the application layout with its sidebar |
guest | Open /welcome while signed out | Shows the guest welcome page; signed-in visitors are redirected away |
optional | Open /public-projects signed in or out | Both identities can open the standalone layout |



Root routes default to required. Descendants inherit auth and cannot change it to another value. Authentication alone does not grant page access.
The current template redirects a protected visit to /login without automatically carrying the original destination. A guest page visited while signed in uses a safe in-app redirect query or returns home. For example, /welcome?redirect=%2Freports%2Fowners sends a signed-in visitor to Owners. Do not assume arbitrary deep links automatically resume after sign-in.
Permission declarations, inheritance and denied access
The complete routes use these authorization declarations:
// Project list and children without their own authorization declaration
authz: { resource: { type: 'page', id: 'projects' }, action: 'access' }
// The draft page requires another page grant
authz: { resource: { type: 'page', id: 'project-drafts' }, action: 'access' }
// Reports skip their own page authorization check but still require sign-in
authz: 'skip'
// Administrator notes require an unrestricted identity
authz: 'unrestricted'In System settings → Permission management → Roles and permissions, create a Project viewer role granting only project page access. Create a demonstration user in Users and assign that role. Sign in with a separate browser session and follow the README to verify:
- The list, details, tasks and workspace are accessible. A child without its own
authzinherits the nearest ancestor page's effective value. - New draft is hidden and
/projects/newis denied. A child's own grant does not replace the parent's check. - Reports remain available through
skip, while still requiring sign-in. - The administrator menu is hidden and
/admin-notes/childis denied. The child'sskipcannot bypass its parent'sunrestrictedrequirement.



An administrator can open Administrator notes → Open child page. unrestricted means an identity with unrestricted access, not every signed-in user.

With no ancestor page to inherit from, an omitted authz defaults to unrestricted for required, or skip for guest and optional. Declare it explicitly on the first page of each tree. Pure groups cannot declare authz.
resource.type, resource.id and action must be nonempty strings. Route names and permission IDs are separate; saved role grants refer to the resource ID. Pages without a navigation or breadcrumb title need a readable name in page-permission-titles.ts, such as projectCreate: 'demo.newDraft'. useCan() controls buttons for the same permission. Frontend page grants do not secure APIs or data bundled into the client. This example's project data is public fiction; see authentication, permissions and data scope for business resources and server enforcement.
Route composition, attachment and overrides
Attach within and across packages
Open Export instructions under Insights at /reports/exports. Another contribution attaches it through parent: 'reportsGroup':
export const appendedRoutes = defineAppRoutes([
{
parent: 'reportsGroup',
name: 'reportExports',
path: 'exports',
authz: 'skip',
navigation: { title: 'demo.exports', order: 10 },
componentLoader: () => import('../examples/exports.js'),
},
]);client/routes.ts deliberately collects appendedRoutes before projectRoutes, showing that the target may be declared later. In a larger application, place contributions in separate files and collect them in a flat array.

reporting-plugin.ts is a client contribution factory kept in this app. @example/project-reporting demonstrates a plugin namespace; it is not a separate npm package to install. Use package:group to attach across packages:
// client/reporting-plugin.ts
{
parent: 'pages-routes-navigation:reportsGroup',
name: 'snapshot',
path: 'snapshot',
authz: 'skip',
navigation: { title: 'demo.snapshot', order: 20 },
componentLoader: () => import('./pages/examples/plugin-original.js'),
}Attaching this entry to the app's reportsGroup produces /reports/snapshot. The route and translation namespace still belong to the plugin, which registers both locales. The shipped configuration enables a component override. Temporarily clear the override array in client/route-overrides.ts to see the original page below, then restore it.

parent is allowed only on contribution root entries and must target a group, not a page. Missing targets, cycles and parent inside existing children fail validation. Add page children through children. Siblings sort by navigation.order; equal values keep existing children first, then appended contributions in registration order.
View app route source · View plugin contribution source
Enable routes through plugin options
A plugin's routes can be a synchronous function of its registration options. reporting-plugin.ts uses enabled to decide whether to contribute its page:
// client/reporting-plugin.ts (excerpt)
export default defineClientPlugin<{ enabled?: boolean }>({
packageName: '@example/project-reporting',
// The complete file also registers en-US and zh-CN locales.
routes: (options) => defineAppRoutes(options.enabled === false ? [] : [
{
parent: 'pages-routes-navigation:reportsGroup',
name: 'snapshot',
path: 'snapshot',
authz: 'skip',
navigation: { title: 'demo.snapshot', order: 20 },
componentLoader: () => import('./pages/examples/plugin-original.js'),
},
]),
});
// Inside the defineClientPlugins array in client/plugins.ts
reportingPlugin({ enabled: true }),routes(options) is a synchronous registration function returning one contribution or a flat array. It does not run again when React state or the current user changes. To try disabling the contribution, change enabled to false and clear the component override array to [] so it does not target an absent route. Restore both afterward. An isolated test also covers this option.

Replace page components
The default example displays a custom Reporting snapshot. Target its package:route ID to replace the component:
// client/route-overrides.ts
import { defineClientRouteComponentOverrides } from '@nocobase/app-client/plugins';
export default defineClientRouteComponentOverrides([
{
routeId: '@example/project-reporting:snapshot',
componentEntry: './client/pages/examples/plugin-custom',
componentLoader: () => import('./pages/examples/plugin-custom.js'),
},
]);
// client/runtime.ts (excerpt)
import routeComponentOverrides from './route-overrides.js';
const appRuntime = defineAppRuntime({
// Retain createAppConfig, locales, routes, plugins and other existing options.
routeComponentOverrides,
});The runtime does not discover route-overrides.ts automatically: pass it explicitly to defineAppRuntime(). An override preserves the path, authorization, navigation, owning package and children. The component still runs under the original package's translation namespace. componentEntry records the source entry; componentLoader loads the component.

Temporarily use an empty override array to see the original component, then restore it. Targets must be registered pages, not groups; each ID may be overridden only once. Do not register a duplicate path to replace a page.
View override source · View runtime registration source
Loading states and error handling
Page loading and failures
Try a slow page opens /route-status/loading. This demonstration loader waits 1.2 seconds to expose the template's loading state:
{
name: 'slowPage',
path: '/route-status/loading',
authz: 'skip',
componentLoader: async () => {
await new Promise((resolve) => setTimeout(resolve, 1200));
return import('../examples/loaded.js');
},
}

Try a page error opens /route-status/error. Its component deliberately throws to demonstrate the ClientRoute error interface. Do not keep this intentional exception in a production page. Reload after fixing the component or network problem. A rejected loader Promise reaches the same error interface.

View loader source · View template error handling source
Handle unmatched addresses
Try an unknown address opens the unregistered /unknown-example. The current app-router.tsx redirects it to the home page. This fallback belongs to the application template; defineAppRoutes() does not accept path: '*'.

Route configuration reference
Configuration fields and defaults
| Field | Page | Pure group |
|---|---|---|
name | Required, unique within its package | Required, unique within its package |
path | Required | Optional prefix for children |
componentLoader | Required | Not allowed |
children | Optional | Required; may be empty |
navigation | Optional; { title, icon?, order? } | Required |
breadcrumb | Optional; { title } | Optional |
auth | Optional; roots default to required, descendants inherit | Optional; passed to descendants |
authz | Optional; declare explicitly on the first page | Not allowed |
parent | Optional, contribution roots only | Optional, contribution roots only |
Names start with a letter or digit and may then contain letters, digits, dots, underscores and hyphens. Titles are strings and icons are components, not per-user configuration callbacks. React Router fields such as index, element, loader, action and errorElement are not fields of this declaration API.
Path rules and conflict checks
- Top-level page paths start with
/. Child paths append to the parent: bothnewand/newappend; the latter does not jump to the root. Repeated and trailing slashes are normalized. - Keep queries and hashes out of
path. Wildcards*, optional parameters?, backslashes, and.or..segments are unsupported. - Page addresses are unique across the app and its plugins. Conflicts ignore static segment case and parameter names:
/Projectsconflicts with/projects, and/:idconflicts with/:projectId. Staticnewcan coexist with:projectId. - Names must be unique within a package across files, groups and levels. Different packages may reuse a name, but not a page address.
- Only the application may contribute
/./login,/register,/forgot-passwordand/reset-passwordmust useauth: 'guest'.
Invalid definitions stay out of the running app. routing-contract.test.ts reproduces rejection cases in isolation.
Example source and setup
Environment and startup
The example app uses default template 1.0.0-beta.85 and locks @nocobase/app-client to 4.0.0-beta.5. It requires Node.js 24 and pnpm 11.11.0.
git clone https://github.com/nocobase/docs-examples-v3.git
cd docs-examples-v3
git checkout 2700e75f5ed0d927c0c37b53e4ffdf105961cc52
cd apps/pages-routes-navigation
npm pkg set packageManager=pnpm@11.11.0
pnpm install --frozen-lockfile
pnpm nocobase config init --dialect sqlite
pnpm nocobase config check
pnpm devSQLite is the demonstration and verification environment for this example. It needs no separate database service; it is not a routing requirement. To open the app from another device, set the listening address and app.publicOrigin as described in the example README, then open /main/ on that address. The local config.yml defines the initial account under users.initialAdmin.
The home page links to each demo. Projects and tasks are public fictional fixtures. New draft demonstrates routing and form state without saving business records. Users, roles and authentication use the app's real SQLite database.

Verify the example
Run from the example directory:
pnpm typecheck
pnpm exec vitest run tests/client/client-routes.test.ts tests/client/routing-contract.test.ts tests/client/routing-behavior.test.tsx tests/client/app-locale-coverage.test.ts tests/client/page-permission-titles.test.ts
pnpm buildClient interaction tests use controlled authorization responses to check nested close, query preservation, default tabs, denied access and draft confirmation. They do not replace real-account checks. The README records browser verification, screenshot reproduction commands and the tested environment.