Skip to Content

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.tsx

What 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 /> from react-router.
  • meta (root layout only, optional): siteName, description, lang (default vi), noindex. noindex: true here applies to every page; a public page opts back in with noindex: 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.
  • AppShell takes theme={APP_THEME} from theme.tsx. If you build the frame yourself with a ConfigProvider that sets theme, read APP_THEME so the owner can still change the look.
  • AppShell also registers the vnd and vnDate column types, so tables show money and dates the Vietnamese way.
  • An app with 2+ pages and no app/layout.tsx gets the check warning contract.no-layout: users have no menu and no sign-out.
  • useRoutes() from app/hooks lists the registered routes, handy for a menu.

Next steps

Last updated