Pages and layouts
≈ 10 min · you will have an order list page, a page per order and a shared frame with a menu.
Each page.tsx is a page at the URL of its folder, for example app/customers/page.tsx is the page /customers. layout.tsx wraps the pages below it, nesting from the root down.
Pages and layouts are .tsx files that run in the browser. Apps use react-router, and manh.run builds the route table from the folder tree, so you declare no routes.
Folders become URLs
app/
├── layout.tsx wraps every page
├── page.tsx /
├── orders/
│ ├── layout.tsx wraps /orders and /orders/:id
│ ├── page.tsx /orders
│ ├── stats/page.tsx /orders/stats
│ └── [id:int]/page.tsx /orders/12
└── (admin)/
├── layout.tsx wraps /users
└── users/page.tsx /users[id:int]is a typed dynamic segment (int,uuid,slug). A value of the wrong type (/orders/abc) shows the built-in 404 page.- A static segment wins:
/orders/statsgoes tostats/page.tsx, not to[id:int]/page.tsx. (admin)is a route group: it groups files and shares a layout and middleware, but adds nothing to the URL.app/(admin)/users/page.tsxis/users, not/admin/users.
Pages
page.tsx exports as default a React component that takes no props. Read URL parameters with useParams(); values are always strings.
import { useParams } from "react-router";
import { PageContainer, ProDescriptions } from "@ant-design/pro-components";
import { useRequest } from "app/hooks";
import { useApiClient } from "app/api";
export default function OrderDetailPage() {
const { id } = useParams();
const api = useApiClient();
const { data, loading } = useRequest(() => api.orders.detail(Number(id)), { refreshDeps: [id] });
return (
<PageContainer title={`Order #${id}`} loading={loading}>
<ProDescriptions column={2} dataSource={data} columns={[
{ title: "Customer", dataIndex: "customerName" },
{ title: "Total", dataIndex: "total", valueType: "vnd" },
]} />
</PageContainer>
);
}The list page and the detail page of one resource usually need only <ResourceList> and <ResourceDetail> from manh/shell; see Data fetching.
Layouts
layout.tsx wraps every page in its folder and its subfolders, in order: root layout → child layout → page. Every layout must render <Outlet />, which is where the child page appears.
The root layout holds the app frame. AppShell from manh/shell already includes the Vietnamese antd locale, antd’s App, the menu per role, sign-out and <Outlet />. The layout file only lists the menu:
import { AppShell } from "manh/shell";
import { getUser, signOut } from "app/hooks";
import { APP_THEME } from "app/theme";
export const meta = { siteName: "Spa Hoa Sen", description: "Herbal spa in Huế", lang: "vi" };
const MENU = [
{ path: "/", name: "Overview" },
{ path: "/orders", name: "Orders" },
{ path: "/users", name: "Users", roles: ["admin"] },
];
export default function RootLayout() {
return <AppShell appName="Spa Hoa Sen" menu={MENU} user={getUser()} onSignOut={signOut} theme={APP_THEME} />;
}Colour, corner radius and dark mode come from app/theme.tsx; see Styling. A child layout usually only adds what one group of pages shares:
import { Outlet } from "react-router";
import { Alert } from "antd";
export default function OrdersLayout() {
return (
<>
<Alert type="info" showIcon message="Orders after 17:00 ship the next day" />
<Outlet />
</>
);
}Page meta
A page or the root layout exports a meta object with literal values. On deploy, manh.run writes it into the route’s <head>, so Google and link previews on Zalo or Facebook read it without running the app.
export const meta = {
title: "Pricing", // → "Pricing · Spa Hoa Sen"
description: "Prices for hair wash, massage and treatments",
image: "https://storage.manh.run/…/public/pricing.jpg",
};- Page keys:
title,description(up to 300 characters),image(absolutehttps://URL),noindex. Root layout keys:siteName,description,lang(defaultvi). - Literal values only. Variables,
${}templates and function calls are ignored, andcheckwarnsseo.dynamic-meta. Routes with parameters use the home page’s<head>. - Images: upload to file storage under the
public/key, then get the URL withblob.getUrl(key)frommanh/blob. - Apps with sign-in: set
meta = { noindex: true }inapp/layout.tsx. Public pages (listed in an array such asPUBLIC_PAGESin the layout) setnoindex: falsewith their owntitleanddescription.
Good to know
- A layout without
<Outlet />hides its child pages.AppShellalready renders<Outlet />. - Don’t use
onBackonPageContainer: the back icon crashes the page. Put aButtonwithArrowLeftOutlinedat the top of the page instead. app/(admin)/page.tsxhas the same URL asapp/page.tsx;checkreportsduplicate page. For a page at/admin, use a plainapp/admin/folder.- An app with 2 or more pages and no
app/layout.tsxgets thecheckwarningcontract.no-layout. useRoutes()fromapp/hooksreturns the registered routes, for when you build a menu yourself.
Next steps
- Styling — colour, corner radius and dark mode for the whole app in
app/theme.tsx. - App shell and page header — menu per role, page header, back button.
- page.tsx and layout.tsx — every export, dynamic segments and
metakeys.