Skip to Content

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/stats goes to stats/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.tsx is /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.

app/orders/[id:int]/page.tsx
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:

app/layout.tsx
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:

app/orders/layout.tsx
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.

app/pricing/page.tsx
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 (absolute https:// URL), noindex. Root layout keys: siteName, description, lang (default vi).
  • Literal values only. Variables, ${} templates and function calls are ignored, and check warns seo.dynamic-meta. Routes with parameters use the home page’s <head>.
  • Images: upload to file storage under the public/ key, then get the URL with blob.getUrl(key) from manh/blob.
  • Apps with sign-in: set meta = { noindex: true } in app/layout.tsx. Public pages (listed in an array such as PUBLIC_PAGES in the layout) set noindex: false with their own title and description.

Good to know

  • A layout without <Outlet /> hides its child pages. AppShell already renders <Outlet />.
  • Don’t use onBack on PageContainer: the back icon crashes the page. Put a Button with ArrowLeftOutlined at the top of the page instead.
  • app/(admin)/page.tsx has the same URL as app/page.tsx; check reports duplicate page. For a page at /admin, use a plain app/admin/ folder.
  • An app with 2 or more pages and no app/layout.tsx gets the check warning contract.no-layout.
  • useRoutes() from app/hooks returns the registered routes, for when you build a menu yourself.

Next steps

Last updated