React Component Writing Guide
- Use antd-style for complex styles; for simple cases, use inline
style attribute
- Use
Flexbox and Center from @lobehub/ui for layouts (see references/layout-kit.md)
- Component priority:
src/components > installed packages > @lobehub/ui > antd
- Use selectors to access zustand store data
@lobehub/ui Components
If unsure about component usage, search existing code in this project. Most components extend antd with additional props.
Reference: node_modules/@lobehub/ui/es/index.mjs for all available components.
Common Components:
- General: ActionIcon, ActionIconGroup, Block, Button, Icon
- Data Display: Avatar, Collapse, Empty, Highlighter, Markdown, Tag, Tooltip
- Data Entry: CodeEditor, CopyButton, EditableText, Form, FormModal, Input, SearchBar, Select
- Feedback: Alert, Drawer, Modal
- Layout: Center, DraggablePanel, Flexbox, Grid, Header, MaskShadow
- Navigation: Burger, Dropdown, Menu, SideNav, Tabs
Routing Architecture
Hybrid routing: Next.js App Router (static pages) + React Router DOM (main SPA).
| Route Type |
Use Case |
Implementation |
| Next.js App Router |
Auth pages (login, signup, oauth) |
src/app/[variants]/(auth)/ |
| React Router DOM |
Main SPA (chat, settings) |
desktopRouter.config.tsx |
Key Files
- Entry:
src/spa/entry.web.tsx (web), src/spa/entry.mobile.tsx, src/spa/entry.desktop.tsx
- Desktop router:
src/spa/router/desktopRouter.config.tsx
- Mobile router:
src/spa/router/mobileRouter.config.tsx
- Router utilities:
src/utils/router.tsx
Router Utilities
import { dynamicElement, redirectElement, ErrorBoundary } from '@/utils/router';
element: dynamicElement(() => import('./chat'), 'Desktop > Chat');
element: redirectElement('/settings/profile');
errorElement: <ErrorBoundary resetPath="/chat" />;
Navigation
Important: For SPA pages, use Link from react-router-dom, NOT next/link.
// ❌ Wrong
import Link from 'next/link';
<Link href="/">Home</Link>;
// ✅ Correct
import { Link } from 'react-router-dom';
<Link to="/">Home</Link>;
// In components
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate('/chat');
// From stores
const navigate = useGlobalStore.getState().navigate;
navigate?.('/settings');
1---2name: react3description: React component development guide. Use when working with React components (.tsx files), creating UI, using @lobehub/ui components, implementing routing, or building frontend features. Triggers on React component creation, modification, layout implementation, or navigation tasks.4---56# React Component Writing Guide78- Use antd-style for complex styles; for simple cases, use inline `style` attribute9- Use `Flexbox` and `Center` from `@lobehub/ui` for layouts (see `references/layout-kit.md`)10- Component priority: `src/components` > installed packages > `@lobehub/ui` > antd11- Use selectors to access zustand store data1213## @lobehub/ui Components1415If unsure about component usage, search existing code in this project. Most components extend antd with additional props.1617Reference: `node_modules/@lobehub/ui/es/index.mjs` for all available components.1819**Common Components:**2021- General: ActionIcon, ActionIconGroup, Block, Button, Icon22- Data Display: Avatar, Collapse, Empty, Highlighter, Markdown, Tag, Tooltip23- Data Entry: CodeEditor, CopyButton, EditableText, Form, FormModal, Input, SearchBar, Select24- Feedback: Alert, Drawer, Modal25- Layout: Center, DraggablePanel, Flexbox, Grid, Header, MaskShadow26- Navigation: Burger, Dropdown, Menu, SideNav, Tabs2728## Routing Architecture2930Hybrid routing: Next.js App Router (static pages) + React Router DOM (main SPA).3132| Route Type | Use Case | Implementation |33| ------------------ | --------------------------------- | ---------------------------- |34| Next.js App Router | Auth pages (login, signup, oauth) | `src/app/[variants]/(auth)/` |35| React Router DOM | Main SPA (chat, settings) | `desktopRouter.config.tsx` |3637### Key Files3839- Entry: `src/spa/entry.web.tsx` (web), `src/spa/entry.mobile.tsx`, `src/spa/entry.desktop.tsx`40- Desktop router: `src/spa/router/desktopRouter.config.tsx`41- Mobile router: `src/spa/router/mobileRouter.config.tsx`42- Router utilities: `src/utils/router.tsx`4344### Router Utilities4546```tsx47import { dynamicElement, redirectElement, ErrorBoundary } from '@/utils/router';4849element: dynamicElement(() => import('./chat'), 'Desktop > Chat');50element: redirectElement('/settings/profile');51errorElement: <ErrorBoundary resetPath="/chat" />;52```5354### Navigation5556**Important**: For SPA pages, use `Link` from `react-router-dom`, NOT `next/link`.5758```tsx59// ❌ Wrong60import Link from 'next/link';61<Link href="/">Home</Link>;6263// ✅ Correct64import { Link } from 'react-router-dom';65<Link to="/">Home</Link>;6667// In components68import { useNavigate } from 'react-router-dom';69const navigate = useNavigate();70navigate('/chat');7172// From stores73const navigate = useGlobalStore.getState().navigate;74navigate?.('/settings');75```