@donotdev/ui 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{GoToDialog-CR4VOVXT.js → GoToDialog-RU5RP7S2.js} +1 -1
- package/dist/chunk-ETE4RC7M.js +1 -0
- package/dist/components/auth/AuthHeader.d.ts +6 -1
- package/dist/components/auth/AuthHeader.d.ts.map +1 -1
- package/dist/components/auth/AuthHeader.js +4 -4
- package/dist/components/common/FeatureCard.d.ts +2 -0
- package/dist/components/common/FeatureCard.d.ts.map +1 -1
- package/dist/components/common/FeatureDisabled.d.ts +1 -0
- package/dist/components/common/FeatureDisabled.d.ts.map +1 -1
- package/dist/components/common/TechBento.d.ts +1 -0
- package/dist/components/common/TechBento.d.ts.map +1 -1
- package/dist/components/common/icon.d.ts +1 -0
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/cookie-consent/CookieConsent.d.ts +1 -0
- package/dist/components/cookie-consent/CookieConsent.d.ts.map +1 -1
- package/dist/components/layout/PageConfig.d.ts +25 -0
- package/dist/components/layout/PageConfig.d.ts.map +1 -0
- package/dist/components/layout/PageConfig.js +47 -0
- package/dist/components/layout/components/Breadcrumbs.d.ts +2 -0
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts +1 -0
- package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppBranding.d.ts +1 -0
- package/dist/components/layout/components/header/AppBranding.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppIcon.d.ts +1 -0
- package/dist/components/layout/components/header/AppIcon.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppTitle.d.ts +1 -0
- package/dist/components/layout/components/header/AppTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/CacheSettings.js +2 -2
- package/dist/components/layout/components/header/GameTitle.d.ts +1 -0
- package/dist/components/layout/components/header/GameTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/HeaderMenu.d.ts +1 -0
- package/dist/components/layout/components/header/HeaderMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/HeaderNavigation.d.ts +1 -0
- package/dist/components/layout/components/header/HeaderNavigation.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.d.ts +1 -0
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/index.d.ts +1 -0
- package/dist/components/layout/index.d.ts.map +1 -1
- package/dist/components/layout/index.js +1 -0
- package/dist/crud/components/EntityCardList.d.ts +1 -1
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- package/dist/crud/components/EntityCardList.js +32 -21
- package/dist/crud/components/EntityDisplayRenderer.d.ts +1 -1
- package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityDisplayRenderer.js +13 -12
- package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityFormRenderer.js +16 -18
- package/dist/crud/components/EntityList.d.ts +1 -1
- package/dist/crud/components/EntityList.d.ts.map +1 -1
- package/dist/crud/components/EntityList.js +40 -24
- package/dist/crud/components/EntityRecommendations.d.ts +1 -1
- package/dist/crud/components/EntityRecommendations.d.ts.map +1 -1
- package/dist/crud/components/EntityRecommendations.js +4 -4
- package/dist/crud/crudImports.d.ts +1 -0
- package/dist/crud/crudImports.d.ts.map +1 -1
- package/dist/crud/crudImports.js +1 -0
- package/dist/dndev-next.css +198 -75
- package/dist/dndev.css +228 -74
- package/dist/index.js +4 -4
- package/dist/internal/common/ErrorFallback.js +1 -1
- package/dist/internal/devtools/DebugTools.js +1 -1
- package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/DesignTab.js +6 -2
- package/dist/internal/devtools/utils/envVarDiscovery.d.ts.map +1 -1
- package/dist/internal/devtools/utils/envVarDiscovery.js +4 -5
- package/dist/internal/devtools/utils/virtualModuleInspector.d.ts.map +1 -1
- package/dist/internal/devtools/utils/virtualModuleInspector.js +2 -0
- package/dist/internal/initializers/BaseStoresInitializer.d.ts.map +1 -1
- package/dist/internal/initializers/BaseStoresInitializer.js +11 -2
- package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
- package/dist/internal/layout/DnDevLayout.js +39 -16
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +55 -23
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +2 -0
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.js +45 -15
- package/dist/internal/layout/components/PWAUpdateNotification.d.ts.map +1 -1
- package/dist/internal/layout/components/PWAUpdateNotification.js +15 -2
- package/dist/internal/layout/zones/DnDevFooter.d.ts +3 -1
- package/dist/internal/layout/zones/DnDevFooter.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevFooter.js +5 -1
- package/dist/internal/layout/zones/DnDevHeader.d.ts +3 -1
- package/dist/internal/layout/zones/DnDevHeader.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevHeader.js +7 -2
- package/dist/internal/layout/zones/DnDevSidebar.d.ts +3 -1
- package/dist/internal/layout/zones/DnDevSidebar.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevSidebar.js +9 -3
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +3 -1
- package/dist/routing/AuthGuard.d.ts +7 -22
- package/dist/routing/AuthGuard.d.ts.map +1 -1
- package/dist/routing/AuthGuard.js +19 -64
- package/dist/routing/AuthReturnTo.d.ts +13 -0
- package/dist/routing/AuthReturnTo.d.ts.map +1 -0
- package/dist/routing/AuthReturnTo.js +61 -0
- package/dist/routing/DnDevNavigationMenu.d.ts +1 -0
- package/dist/routing/DnDevNavigationMenu.d.ts.map +1 -1
- package/dist/routing/GoTo.d.ts +1 -0
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/useNavigate.next.d.ts +8 -0
- package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.next.js +58 -8
- package/dist/routing/hooks/useNavigate.vite.d.ts +8 -0
- package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.vite.js +64 -14
- package/dist/routing/hooks/useRedirectGuard.next.d.ts +2 -0
- package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.next.js +11 -27
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts +2 -0
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.vite.js +11 -27
- package/dist/routing/index.d.ts +1 -0
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -0
- package/dist/styles/index.css +228 -74
- package/dist/symbol-index.json +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/sanitizeSvg.d.ts +4 -0
- package/dist/utils/sanitizeSvg.d.ts.map +1 -1
- package/dist/utils/sanitizeSvg.js +4 -0
- package/dist/utils/useAISafe.d.ts +28 -0
- package/dist/utils/useAISafe.d.ts.map +1 -0
- package/dist/utils/useAISafe.js +53 -0
- package/dist/utils/useAuthSafe.d.ts +39 -0
- package/dist/utils/useAuthSafe.d.ts.map +1 -1
- package/dist/utils/useAuthSafe.js +5 -0
- package/dist/utils/useAuthVisibility.d.ts +1 -0
- package/dist/utils/useAuthVisibility.d.ts.map +1 -1
- package/dist/utils/useBillingVisibility.d.ts +1 -0
- package/dist/utils/useBillingVisibility.d.ts.map +1 -1
- package/dist/utils/useSeo.d.ts +121 -0
- package/dist/utils/useSeo.d.ts.map +1 -0
- package/dist/utils/useSeo.js +114 -0
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +14 -4
- package/dist/vite-routing/RootLayout.d.ts.map +1 -1
- package/dist/vite-routing/RootLayout.js +6 -4
- package/guidelines/COMPONENTS.md +136 -0
- package/guidelines/GOTCHAS.md +66 -0
- package/guidelines/LAYOUTS.md +310 -0
- package/guidelines/PAGES.md +205 -0
- package/guidelines/ROUTING.md +499 -0
- package/guidelines/SEO.md +275 -0
- package/package.json +12 -7
- package/dist/chunk-XHGRMKOY.js +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Pages & Routing
|
|
2
|
+
|
|
3
|
+
**Drop `*Page.tsx` files. Routes auto-discovered, navigation auto-generated, sitemap auto-built.**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## File Routing Rule
|
|
8
|
+
|
|
9
|
+
**CRITICAL: Only files ending in `Page.tsx` inside `src/pages` become routes.**
|
|
10
|
+
|
|
11
|
+
Files must be named `*Page.tsx` (e.g., `HomePage.tsx`, `AboutPage.tsx`, `BlogPostPage.tsx`). Files without the `Page.tsx` suffix are ignored by the routing system.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Standard Use
|
|
16
|
+
|
|
17
|
+
**Pattern:** `src/pages/**/*Page.tsx` - routes
|
|
18
|
+
|
|
19
|
+
**Basic page structure:**
|
|
20
|
+
```tsx
|
|
21
|
+
// src/pages/AboutPage.tsx
|
|
22
|
+
import { PageContainer } from '@donotdev/ui';
|
|
23
|
+
|
|
24
|
+
export const NAMESPACE = 'about';
|
|
25
|
+
|
|
26
|
+
export const meta: PageMeta = {
|
|
27
|
+
namespace: NAMESPACE,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default function AboutPage() {
|
|
31
|
+
return <PageContainer><h1>About</h1></PageContainer>;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Cookie-cutter pattern (Landing page):**
|
|
36
|
+
```tsx
|
|
37
|
+
import { PageContainer } from '@donotdev/ui';
|
|
38
|
+
import { HeroSection, Section, Card, CallToAction } from '@donotdev/components';
|
|
39
|
+
|
|
40
|
+
export default function HomePage() {
|
|
41
|
+
return (
|
|
42
|
+
<PageContainer>
|
|
43
|
+
<HeroSection title="Welcome" subtitle="Build fast" variant="primary" />
|
|
44
|
+
<Section title="Features" gridCols={3}>
|
|
45
|
+
<Card title="Fast" />
|
|
46
|
+
<Card title="Simple" />
|
|
47
|
+
<Card title="Powerful" />
|
|
48
|
+
</Section>
|
|
49
|
+
<CallToAction title="Get Started" primaryAction={<Button>Sign Up</Button>} />
|
|
50
|
+
</PageContainer>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Drop files, get routes. No config needed.**
|
|
56
|
+
|
|
57
|
+
**Component reference:** See the `@donotdev/components` guidelines for atomic components, and the COMPONENTS guideline for layout components.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Advanced: All PageMeta Props
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
export const meta: PageMeta = {
|
|
65
|
+
// Translation/SEO namespace
|
|
66
|
+
namespace: NAMESPACE,
|
|
67
|
+
|
|
68
|
+
// Route configuration
|
|
69
|
+
route: '/custom-url', // Override auto-generated path
|
|
70
|
+
route: { params: ['slug'] }, // Dynamic: /blog/:slug
|
|
71
|
+
|
|
72
|
+
// Page title (optional - auto-extracted from filename)
|
|
73
|
+
title: 'Custom Title',
|
|
74
|
+
|
|
75
|
+
// Navigation icon (lucide-react JSX only)
|
|
76
|
+
icon: <Rocket />, // Menu icon (default: Link)
|
|
77
|
+
|
|
78
|
+
// Hide from navigation menu
|
|
79
|
+
hideFromMenu: false, // Default: false (shows in nav)
|
|
80
|
+
|
|
81
|
+
// Layout preset override (per-route)
|
|
82
|
+
preset: 'admin', // Override app default for this route
|
|
83
|
+
|
|
84
|
+
// Authentication
|
|
85
|
+
auth: true, // Simple: auth required
|
|
86
|
+
auth: { required: true }, // Explicit: auth required
|
|
87
|
+
auth: { required: true, role: 'admin' }, // Role-based access
|
|
88
|
+
auth: { required: true, tier: 'pro' }, // Tier-based access
|
|
89
|
+
auth: {
|
|
90
|
+
required: true,
|
|
91
|
+
validate: (role, tier) => role === 'admin' && tier === 'pro'
|
|
92
|
+
}, // Custom validation
|
|
93
|
+
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Reference implementation:** The demo app (`packages/cli/templates/app-demo/`) shows all these patterns working together - landing, admin, docs presets, auth, showcase, CRUD, legal pages.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Advanced: Dynamic Routes & Navigation
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
// Dynamic route
|
|
104
|
+
export const meta: PageMeta = {
|
|
105
|
+
namespace: 'blog',
|
|
106
|
+
route: { params: ['slug'] }, // /blog/:slug
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default function BlogPostPage() {
|
|
110
|
+
const { slug } = useParams<{ slug: string }>();
|
|
111
|
+
return <PageContainer><h1>{slug}</h1></PageContainer>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Manual navigation
|
|
115
|
+
import { useNavigate, Link } from '@donotdev/ui';
|
|
116
|
+
const navigate = useNavigate();
|
|
117
|
+
navigate('/about');
|
|
118
|
+
<Link path="/about">About</Link>
|
|
119
|
+
|
|
120
|
+
// Card with navigation (supports middle-click)
|
|
121
|
+
import { Card } from '@donotdev/components';
|
|
122
|
+
import { Link } from '@donotdev/ui';
|
|
123
|
+
|
|
124
|
+
<Link
|
|
125
|
+
path="/about"
|
|
126
|
+
style={{ display: 'block', textDecoration: 'none', height: '100%' }}
|
|
127
|
+
aria-label="Learn more about About"
|
|
128
|
+
>
|
|
129
|
+
<Card title="About" subtitle="Learn more" />
|
|
130
|
+
</Link>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Navigation patterns:**
|
|
134
|
+
- **Link component:** Use for text links, buttons, or wrapping other components
|
|
135
|
+
- **Card navigation:** Wrap Card in Link for clickable cards with middle-click support
|
|
136
|
+
- **onClick only:** Use `onClick={() => navigate()}` for actions that don't need middle-click
|
|
137
|
+
|
|
138
|
+
**Pre-configured:** Navigation menu auto-generated, sitemap auto-built (if `generateSitemap: true`).
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Import Convention
|
|
145
|
+
|
|
146
|
+
**Always import from `@donotdev/<package>` top-level.** Never use sub-paths.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { PageContainer, Link, useNavigate } from '@donotdev/ui';
|
|
150
|
+
import { Card, Button, Input } from '@donotdev/components';
|
|
151
|
+
import { useCrud } from '@donotdev/crud';
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Sub-path exceptions** (server, config, and provider-specific):
|
|
155
|
+
- **Server:** `@donotdev/core/server`, `@donotdev/firebase/server`, `@donotdev/security/server`
|
|
156
|
+
- **Config:** `@donotdev/core/vite`, `@donotdev/core/next`, `@donotdev/core/functions`
|
|
157
|
+
- **Functions:** `@donotdev/functions/firebase`, `@donotdev/functions/vercel`, `@donotdev/functions/supabase`
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## SaaS App Pattern
|
|
162
|
+
|
|
163
|
+
For SaaS apps, the standard page structure is:
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
src/pages/
|
|
167
|
+
HomePage.tsx -> / -> No auth. Login form OR landing page.
|
|
168
|
+
Redirects to /dashboard when authenticated.
|
|
169
|
+
DashboardPage.tsx -> /dashboard -> auth: true. Main landing for logged-in users.
|
|
170
|
+
SettingsPage.tsx -> /settings -> auth: true.
|
|
171
|
+
...
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**HomePage is never auth-guarded.** It's the entry point for unauthenticated users. Do NOT create a separate `LoginPage` - HomePage IS the login.
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
// src/pages/HomePage.tsx - SaaS pattern
|
|
178
|
+
import { useAuthSafe, useNavigate, PageContainer } from '@donotdev/ui';
|
|
179
|
+
import { LoginForm } from '@donotdev/templates';
|
|
180
|
+
|
|
181
|
+
export const meta: PageMeta = {
|
|
182
|
+
namespace: 'home',
|
|
183
|
+
// No auth - this is the public entry point
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export default function HomePage() {
|
|
187
|
+
const user = useAuthSafe('user');
|
|
188
|
+
const navigate = useNavigate();
|
|
189
|
+
|
|
190
|
+
// Redirect authenticated users to dashboard
|
|
191
|
+
if (user) { navigate('/dashboard'); return null; }
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<PageContainer>
|
|
195
|
+
<LoginForm onSuccess={() => navigate('/dashboard')} />
|
|
196
|
+
</PageContainer>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
> **Why `useAuthSafe` instead of `useAuth`?** HomePage is public - it renders before auth is guaranteed to be initialized. `useAuthSafe` (from `@donotdev/ui`) gracefully degrades if `@donotdev/auth` isn't installed or still initializing. `useAuth` (from `@donotdev/auth`) throws if auth isn't available. Use `useAuthSafe` on any page without `auth: true` in its meta.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
**Drop files, get routes. Framework handles the rest.**
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# Routing
|
|
2
|
+
|
|
3
|
+
**Use framework routing components/hooks. NEVER import from `react-router-dom` directly.** Framework handles SPA navigation, Outlet, and overlay closing automatically.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Critical Rule: Never Use react-router-dom Directly
|
|
8
|
+
|
|
9
|
+
**WRONG:**
|
|
10
|
+
```tsx
|
|
11
|
+
import { Link, useNavigate, useParams } from 'react-router-dom'; // BREAKS FRAMEWORK
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**CORRECT:**
|
|
15
|
+
```tsx
|
|
16
|
+
import { Link, useNavigate, useParams } from '@donotdev/ui'; // Framework routing
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Why?** The framework's routing components:
|
|
20
|
+
- Automatically close overlays on navigation
|
|
21
|
+
- Handle SPA navigation correctly with Outlet
|
|
22
|
+
- Work with both Vite and Next.js
|
|
23
|
+
- Integrate with auth and route discovery
|
|
24
|
+
- Provide proper TypeScript types
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Framework Routing API
|
|
29
|
+
|
|
30
|
+
### Components
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { Link, DnDevNavigationMenu } from '@donotdev/ui';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Link Component:**
|
|
37
|
+
```tsx
|
|
38
|
+
<Link path="/products" label="Products" icon="Package" />
|
|
39
|
+
<Link path="/users/:id" replace prefetch={false}>User Details</Link>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**DnDevNavigationMenu (Sidebar/Header):**
|
|
43
|
+
```tsx
|
|
44
|
+
// Auto-fetches routes, handles auth filtering
|
|
45
|
+
<DnDevNavigationMenu vertical display={DISPLAY.AUTO} />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Hooks
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import {
|
|
52
|
+
useNavigate,
|
|
53
|
+
useLocation,
|
|
54
|
+
useParams,
|
|
55
|
+
useRouteParam,
|
|
56
|
+
useSearchParams,
|
|
57
|
+
useNavigationItems,
|
|
58
|
+
} from '@donotdev/ui';
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Navigation Patterns
|
|
64
|
+
|
|
65
|
+
### 1. Basic Navigation
|
|
66
|
+
|
|
67
|
+
**Use framework Link:**
|
|
68
|
+
```tsx
|
|
69
|
+
import { Link } from '@donotdev/ui';
|
|
70
|
+
|
|
71
|
+
function ProductCard({ product }) {
|
|
72
|
+
return (
|
|
73
|
+
<Link path={`/products/${product.id}`} label={product.name} />
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Use framework useNavigate:**
|
|
79
|
+
```tsx
|
|
80
|
+
import { useNavigate } from '@donotdev/ui';
|
|
81
|
+
|
|
82
|
+
function ProductForm() {
|
|
83
|
+
const navigate = useNavigate();
|
|
84
|
+
|
|
85
|
+
const handleSubmit = async () => {
|
|
86
|
+
await saveProduct();
|
|
87
|
+
navigate('/products'); // Closes overlays automatically
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return <form onSubmit={handleSubmit}>...</form>;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**DON'T use react-router-dom:**
|
|
95
|
+
```tsx
|
|
96
|
+
import { useNavigate } from 'react-router-dom'; // BREAKS FRAMEWORK
|
|
97
|
+
|
|
98
|
+
function ProductForm() {
|
|
99
|
+
const navigate = useNavigate(); // Doesn't close overlays, breaks SPA
|
|
100
|
+
// ...
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### 2. Route Parameters
|
|
107
|
+
|
|
108
|
+
**Use framework useRouteParam:**
|
|
109
|
+
```tsx
|
|
110
|
+
import { useRouteParam } from '@donotdev/ui';
|
|
111
|
+
|
|
112
|
+
function ProductPage() {
|
|
113
|
+
const id = useRouteParam('id'); // Returns string | undefined
|
|
114
|
+
// Safe: handles string | string[] | undefined automatically
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Or use framework useParams:**
|
|
119
|
+
```tsx
|
|
120
|
+
import { useParams } from '@donotdev/ui';
|
|
121
|
+
|
|
122
|
+
function ProductPage() {
|
|
123
|
+
const params = useParams();
|
|
124
|
+
const id = typeof params.id === 'string' ? params.id : undefined;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**DON'T use react-router-dom:**
|
|
129
|
+
```tsx
|
|
130
|
+
import { useParams } from 'react-router-dom'; // Type issues, breaks framework
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### 3. Sidebar Navigation
|
|
136
|
+
|
|
137
|
+
**Use DnDevNavigationMenu (auto-fetches routes):**
|
|
138
|
+
```tsx
|
|
139
|
+
import { DnDevNavigationMenu, DISPLAY } from '@donotdev/ui';
|
|
140
|
+
|
|
141
|
+
function Sidebar() {
|
|
142
|
+
return (
|
|
143
|
+
<DnDevNavigationMenu
|
|
144
|
+
vertical
|
|
145
|
+
display={DISPLAY.AUTO} // CSS-driven collapse
|
|
146
|
+
showIcons={true}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Or use useNavigationItems for custom sidebar:**
|
|
153
|
+
```tsx
|
|
154
|
+
import { Link, useNavigationItems } from '@donotdev/ui';
|
|
155
|
+
|
|
156
|
+
function CustomSidebar() {
|
|
157
|
+
const menuItems = useNavigationItems(); // Auth-filtered routes
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<nav>
|
|
161
|
+
{menuItems.map((item) => (
|
|
162
|
+
<Link
|
|
163
|
+
key={item.path}
|
|
164
|
+
path={item.path}
|
|
165
|
+
label={item.label}
|
|
166
|
+
icon={item.icon}
|
|
167
|
+
className={item.isActive ? 'active' : ''}
|
|
168
|
+
/>
|
|
169
|
+
))}
|
|
170
|
+
</nav>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**DON'T manually build navigation:**
|
|
176
|
+
```tsx
|
|
177
|
+
import { Link } from 'react-router-dom'; // BREAKS FRAMEWORK
|
|
178
|
+
|
|
179
|
+
function Sidebar() {
|
|
180
|
+
// Doesn't integrate with route discovery
|
|
181
|
+
// Doesn't handle auth filtering
|
|
182
|
+
// Doesn't work with Outlet
|
|
183
|
+
return (
|
|
184
|
+
<nav>
|
|
185
|
+
<Link to="/products">Products</Link>
|
|
186
|
+
</nav>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
### 4. Programmatic Navigation
|
|
194
|
+
|
|
195
|
+
**Use framework useNavigate:**
|
|
196
|
+
```tsx
|
|
197
|
+
import { useNavigate } from '@donotdev/ui';
|
|
198
|
+
|
|
199
|
+
function LoginForm() {
|
|
200
|
+
const navigate = useNavigate();
|
|
201
|
+
|
|
202
|
+
const handleLogin = async () => {
|
|
203
|
+
await signIn();
|
|
204
|
+
navigate('/dashboard', { replace: true }); // Closes overlays
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return <form onSubmit={handleLogin}>...</form>;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Navigate back:**
|
|
212
|
+
```tsx
|
|
213
|
+
const navigate = useNavigate();
|
|
214
|
+
navigate('back'); // Framework handles browser history
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**With options:**
|
|
218
|
+
```tsx
|
|
219
|
+
navigate('/products', {
|
|
220
|
+
replace: true, // Replace history entry
|
|
221
|
+
preserveScroll: true, // Preserve scroll position
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
### 5. Query Parameters
|
|
228
|
+
|
|
229
|
+
**Use framework useSearchParams (read-only, returns URLSearchParams directly):**
|
|
230
|
+
```tsx
|
|
231
|
+
import { useSearchParams } from '@donotdev/ui';
|
|
232
|
+
|
|
233
|
+
function ProductList() {
|
|
234
|
+
const searchParams = useSearchParams();
|
|
235
|
+
const page = searchParams.get('page') || '1';
|
|
236
|
+
|
|
237
|
+
return <div>Page: {page}</div>;
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Or use useQueryParams helper:**
|
|
242
|
+
```tsx
|
|
243
|
+
import { useQueryParams } from '@donotdev/ui';
|
|
244
|
+
|
|
245
|
+
function ProductList() {
|
|
246
|
+
const { page, sort } = useQueryParams({ page: '1', sort: 'name' });
|
|
247
|
+
// Returns { page: string, sort: string } with defaults
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
### 6. Route Matching
|
|
254
|
+
|
|
255
|
+
**Use framework useMatch:**
|
|
256
|
+
```tsx
|
|
257
|
+
import { useMatch } from '@donotdev/ui';
|
|
258
|
+
|
|
259
|
+
function NavigationItem({ path }) {
|
|
260
|
+
const isActive = useMatch(path);
|
|
261
|
+
return <Link path={path} className={isActive ? 'active' : ''} />;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Outlet and Nested Routes
|
|
268
|
+
|
|
269
|
+
**Framework handles Outlet automatically.** You don't need to manually use `<Outlet />` in most cases.
|
|
270
|
+
|
|
271
|
+
### How It Works
|
|
272
|
+
|
|
273
|
+
1. **RootLayout** wraps all routes and includes `<Outlet />`
|
|
274
|
+
2. **DnDevLayout** receives `<Outlet />` and renders it in the main content area
|
|
275
|
+
3. **Routes are discovered** from `src/pages/*Page.tsx` files automatically
|
|
276
|
+
|
|
277
|
+
**Your pages just render content:**
|
|
278
|
+
```tsx
|
|
279
|
+
// src/pages/ProductsPage.tsx
|
|
280
|
+
export function ProductsPage() {
|
|
281
|
+
return <div>Products List</div>; // Rendered via Outlet automatically
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**DON'T manually use Outlet:**
|
|
286
|
+
```tsx
|
|
287
|
+
import { Outlet } from 'react-router-dom'; // BREAKS FRAMEWORK
|
|
288
|
+
|
|
289
|
+
export function ProductsPage() {
|
|
290
|
+
return (
|
|
291
|
+
<div>
|
|
292
|
+
<h1>Products</h1>
|
|
293
|
+
<Outlet /> {/* Framework already handles this */}
|
|
294
|
+
</div>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Nested Routes (Advanced)
|
|
300
|
+
|
|
301
|
+
If you need nested routes, use the framework's route discovery:
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
// src/pages/products/ProductsPage.tsx
|
|
305
|
+
export const pageMeta = {
|
|
306
|
+
route: '/products',
|
|
307
|
+
// ...
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// src/pages/products/ProductDetailPage.tsx
|
|
311
|
+
export const pageMeta = {
|
|
312
|
+
route: '/products/:id',
|
|
313
|
+
// ...
|
|
314
|
+
};
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Framework automatically creates nested route structure.
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Route Discovery
|
|
322
|
+
|
|
323
|
+
**Routes are auto-discovered from `src/pages/*Page.tsx` files.**
|
|
324
|
+
|
|
325
|
+
**Define routes with PageMeta:**
|
|
326
|
+
```tsx
|
|
327
|
+
// src/pages/ProductsPage.tsx
|
|
328
|
+
import type { PageMeta } from '@donotdev/core';
|
|
329
|
+
|
|
330
|
+
export const pageMeta: PageMeta = {
|
|
331
|
+
title: 'Products',
|
|
332
|
+
route: '/products',
|
|
333
|
+
icon: 'Package',
|
|
334
|
+
auth: { required: true, roles: ['user', 'admin'] },
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export function ProductsPage() {
|
|
338
|
+
return <div>Products</div>;
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
**Framework automatically:**
|
|
343
|
+
- Discovers routes from filesystem
|
|
344
|
+
- Generates navigation menus
|
|
345
|
+
- Filters by auth permissions
|
|
346
|
+
- Handles lazy loading
|
|
347
|
+
- Creates route structure
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Common Mistakes
|
|
352
|
+
|
|
353
|
+
### Mistake 1: Importing from react-router-dom
|
|
354
|
+
|
|
355
|
+
```tsx
|
|
356
|
+
// WRONG
|
|
357
|
+
import { Link, useNavigate } from 'react-router-dom';
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
**Fix:**
|
|
361
|
+
```tsx
|
|
362
|
+
// CORRECT
|
|
363
|
+
import { Link, useNavigate } from '@donotdev/ui';
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
### Mistake 2: Manual Outlet Usage
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
// WRONG
|
|
372
|
+
import { Outlet } from 'react-router-dom';
|
|
373
|
+
|
|
374
|
+
export function Layout() {
|
|
375
|
+
return <Outlet />; // Framework already handles this
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Fix:** Don't use Outlet manually. Framework handles it.
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
### Mistake 3: Manual Route Configuration
|
|
384
|
+
|
|
385
|
+
```tsx
|
|
386
|
+
// WRONG
|
|
387
|
+
import { Routes, Route } from 'react-router-dom';
|
|
388
|
+
|
|
389
|
+
function App() {
|
|
390
|
+
return (
|
|
391
|
+
<Routes>
|
|
392
|
+
<Route path="/products" element={<ProductsPage />} />
|
|
393
|
+
</Routes>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**Fix:** Use route discovery. Create `src/pages/ProductsPage.tsx` with `pageMeta`.
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
### Mistake 4: Manual Navigation Menu
|
|
403
|
+
|
|
404
|
+
```tsx
|
|
405
|
+
// WRONG
|
|
406
|
+
function Sidebar() {
|
|
407
|
+
return (
|
|
408
|
+
<nav>
|
|
409
|
+
<Link to="/products">Products</Link>
|
|
410
|
+
<Link to="/users">Users</Link>
|
|
411
|
+
</nav>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
**Fix:**
|
|
417
|
+
```tsx
|
|
418
|
+
// CORRECT
|
|
419
|
+
import { DnDevNavigationMenu } from '@donotdev/ui';
|
|
420
|
+
|
|
421
|
+
function Sidebar() {
|
|
422
|
+
return <DnDevNavigationMenu vertical />; // Auto-fetches routes
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
### Mistake 5: Not Using Framework Link
|
|
429
|
+
|
|
430
|
+
```tsx
|
|
431
|
+
// WRONG
|
|
432
|
+
import { Link } from 'react-router-dom';
|
|
433
|
+
|
|
434
|
+
<Link to="/products">Products</Link>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**Fix:**
|
|
438
|
+
```tsx
|
|
439
|
+
// CORRECT
|
|
440
|
+
import { Link } from '@donotdev/ui';
|
|
441
|
+
|
|
442
|
+
<Link path="/products" label="Products" />
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## Quick Reference
|
|
448
|
+
|
|
449
|
+
### Import Paths
|
|
450
|
+
|
|
451
|
+
```tsx
|
|
452
|
+
// Framework routing (platform-agnostic)
|
|
453
|
+
import {
|
|
454
|
+
Link,
|
|
455
|
+
useNavigate,
|
|
456
|
+
useLocation,
|
|
457
|
+
useParams,
|
|
458
|
+
useRouteParam,
|
|
459
|
+
useSearchParams,
|
|
460
|
+
useNavigationItems,
|
|
461
|
+
DnDevNavigationMenu,
|
|
462
|
+
} from '@donotdev/ui';
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### Common Patterns
|
|
466
|
+
|
|
467
|
+
```tsx
|
|
468
|
+
// Navigation
|
|
469
|
+
const navigate = useNavigate();
|
|
470
|
+
navigate('/products');
|
|
471
|
+
navigate('back');
|
|
472
|
+
navigate('/products', { replace: true });
|
|
473
|
+
|
|
474
|
+
// Route params
|
|
475
|
+
const id = useRouteParam('id');
|
|
476
|
+
|
|
477
|
+
// Query params (read-only, returns URLSearchParams directly)
|
|
478
|
+
const searchParams = useSearchParams();
|
|
479
|
+
const page = searchParams.get('page');
|
|
480
|
+
|
|
481
|
+
// Navigation menu
|
|
482
|
+
const menuItems = useNavigationItems(); // Auth-filtered routes
|
|
483
|
+
|
|
484
|
+
// Link component
|
|
485
|
+
<Link path="/products" label="Products" icon="Package" />
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## Summary
|
|
491
|
+
|
|
492
|
+
1. **Always import from `@donotdev/ui`** - never `react-router-dom`
|
|
493
|
+
2. **Use `DnDevNavigationMenu`** for sidebars/headers
|
|
494
|
+
3. **Use `useNavigationItems()`** for custom navigation
|
|
495
|
+
4. **Don't use `<Outlet />` manually** - framework handles it
|
|
496
|
+
5. **Routes are auto-discovered** from `src/pages/*Page.tsx`
|
|
497
|
+
6. **Framework closes overlays** on navigation automatically
|
|
498
|
+
|
|
499
|
+
**Framework handles SPA navigation, Outlet, and route discovery. Use framework components/hooks only.**
|