- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.7k
 
          feat(fetch-router): support nested routes in createResource & createResources
          #10775
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    feat(fetch-router): support nested routes in createResource & createResources
  
  #10775
              Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for nested routes in createResource and createResources functions through a new children option, allowing developers to define child routes inline instead of using object spread syntax.
- Adds 
childrenoption to bothResourceOptionsandResourcesOptionsinterfaces - Implements 
addParamToPatternsutility function to prepend parameters to child route patterns - Updates type definitions to handle nested route structures with proper parameter inheritance
 
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description | 
|---|---|
| packages/fetch-router/src/lib/resource.ts | Adds children option support, implements parameter prefixing logic, and updates type definitions | 
| packages/fetch-router/src/lib/resource.test.ts | Adds comprehensive tests for the new children functionality with various route pattern types | 
| packages/fetch-router/CHANGELOG.md | Documents the new nested routes feature with before/after examples | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const addParamToPatterns = (defs: RouteDefs, param: string): RouteDefs => | ||
| Object.fromEntries( | ||
| Object.entries(defs).map(([key, value]) => { | ||
| let updatedValue = | ||
| value instanceof Route | ||
| ? new Route(value.method, new RoutePattern(`:${param}`).join(value.pattern)) | ||
| : typeof value === 'string' || value instanceof RoutePattern | ||
| ? new RoutePattern(`:${param}`).join(value) | ||
| : typeof value === 'object' && 'pattern' in value | ||
| ? { ...value, pattern: new RoutePattern(`:${param}`).join((value as any).pattern) } | ||
| : addParamToPatterns(value, param) | ||
| 
               | 
          ||
| return [key, updatedValue] | ||
| }), | ||
| ) | 
    
      
    
      Copilot
AI
    
    
    
      Oct 13, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion (value as any).pattern on line 143 bypasses TypeScript's type checking. Consider using a more specific type guard or conditional type checking to ensure type safety.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also done in a couple of other places, hence why I took it over.
If needed, I'm happy to add better typing here
53c7d1b    to
    71c4820      
    Compare
  
    createResource & createResourcescreateResource & createResources
      | 
           Thanks for the PR, @MichaelDeBoey. I think I prefer the object spread syntax here instead of a   | 
    
With this PR
now becomes