layout.tsx
layout.tsx wraps every page in its folder and below, and must render <Outlet /> so the inner page shows.
app/
├── layout.tsx # wraps every page
├── orders/
│ ├── layout.tsx # wraps /orders and /orders/:id
│ ├── page.tsx
│ └── [id:int]/page.tsx
└── (admin)/
├── layout.tsx # wraps /users and /products
├── users/page.tsx
└── products/page.tsxWhat it does
Layouts nest from the root down: root layout, then the folder’s layout, then the page. <Outlet /> is where the inner part shows.
The root layout app/layout.tsx holds the app frame. AppShell from manh/shell already includes antd’s Vietnamese locale, antd’s App, the theme, a menu by role, sign-out and <Outlet />, so the root layout only lists the menu. A nested layout adds what one group of pages shares, such as a notice or a tab bar. A (admin) group lets several pages share a layout without adding a URL segment.
Exports
default: a React component that renders<Outlet />fromreact-router.meta(root layout only, optional):siteName,description,lang(defaultvi),noindex.noindex: truehere applies to every page; a public page opts back in withnoindex: false.
Example
app/layout.tsx
import { AppShell } from "manh/shell";
import { ADMIN_ROLE } from "app/shared/auth-roles";
import { getUser, signOut } from "app/hooks";
import { APP_THEME } from "app/theme";
import { DashboardOutlined, ShoppingCartOutlined, TeamOutlined } from "@ant-design/icons";
export const meta = { siteName: "Hoa Phat Warehouse", lang: "vi", noindex: true };
const MENU = [
{ path: "/", name: "Tổng quan", icon: <DashboardOutlined /> },
{ path: "/orders", name: "Đơn hàng", icon: <ShoppingCartOutlined /> },
{ path: "/users", name: "Người dùng", icon: <TeamOutlined />, roles: [ADMIN_ROLE] }, // admins only
];
export default function RootLayout() {
return <AppShell appName="Hoa Phat Warehouse" menu={MENU} user={getUser()} onSignOut={signOut} theme={APP_THEME} />;
}app/orders/layout.tsx
import { Outlet } from "react-router";
import { Alert } from "antd";
export default function OrdersLayout() {
return (
<>
<Alert type="info" showIcon message="Orders placed after 17:00 ship the next day" />
<Outlet />
</>
);
}Good to know
- Without
<Outlet />inner pages don’t show. AppShelltakestheme={APP_THEME}from theme.tsx. If you build the frame yourself with aConfigProviderthat setstheme, readAPP_THEMEso the owner can still change the look.AppShellalso registers thevndandvnDatecolumn types, so tables show money and dates the Vietnamese way.- An app with 2+ pages and no
app/layout.tsxgets thecheckwarningcontract.no-layout: users have no menu and no sign-out. useRoutes()fromapp/hookslists the registered routes, handy for a menu.
Next steps
- App frame and page header — tune
AppShell’s menu, header and menu groups. - theme.tsx — change the primary color, radius and dark mode for the whole app.
- Pages and layouts — route groups and per-page
meta.
Last updated