2.5 KiB
2.5 KiB
Add Route Command
You are helping the user add a new route to their frontend application following Sngular's routing best practices.
Instructions
-
Detect the framework and routing setup:
- Next.js (App Router or Pages Router)
- React Router
- Vue Router
- Other routing solution
-
Ask for route details:
- Route path (e.g.,
/dashboard,/users/:id) - Route name/title
- Whether it requires authentication
- Parent route (if nested)
- Any route parameters or query params
- Route path (e.g.,
-
Determine route type:
- Public route
- Protected route (requires authentication)
- Nested route
- Dynamic route with parameters
- Layout route
Implementation Tasks
For Next.js App Router:
- Create the route directory structure:
app/[route-path]/page.tsx - Add layout if needed:
app/[route-path]/layout.tsx - Add loading state:
app/[route-path]/loading.tsx - Add error boundary:
app/[route-path]/error.tsx - Add metadata for SEO
- Implement the page component
For Next.js Pages Router:
- Create page file in
pages/directory - Add getServerSideProps or getStaticProps if needed
- Configure route in middleware for protection
For React Router:
- Create the page component
- Add route configuration in router setup
- Add route to navigation
- Set up protected route wrapper if needed
For Vue Router:
- Create the view component
- Add route configuration in
router/index.ts - Add route guards if authentication required
- Update navigation menu
Files to Create/Update
- Page/View Component: Main component for the route
- Route Configuration: Add to routing setup
- Navigation: Update navigation menu/sidebar
- Breadcrumbs: Update breadcrumb configuration if used
- Tests: Add route testing
- Types: Add route-specific TypeScript types
Best Practices
- Use proper SEO metadata (title, description, OG tags)
- Implement loading states
- Add error boundaries
- Use code splitting for better performance
- Add route guards for protected routes
- Follow consistent naming conventions
- Add proper TypeScript types for route params
- Implement skeleton loaders for better UX
- Add proper ARIA landmarks for accessibility
Example Outputs
For a dashboard route in Next.js App Router:
app/dashboard/page.tsx- Main page componentapp/dashboard/layout.tsx- Dashboard layoutapp/dashboard/loading.tsx- Loading stateapp/dashboard/error.tsx- Error boundary
Ask the user: "What route would you like to add to your application?"