Skip to content

Type errors when nested resources have the same name #101

@mk-relax

Description

@mk-relax

Wayfinder Version

0.1.12

Laravel Version

12.30.1

PHP Version

8.4.12

Description

I have API routes for resources that have nested resources with the same name, e.g. folders/{id}/folders for folder structures or teams/{id}/teams for teams that have sub-teams etc.

When the route name contains the resource twice, e.g. folders.folders.index, the generated routes/folders/index.ts would contain:

const folders = {
    ...
    folders: Object.assign(folders, folders),
}

This results in an error: Uncaught (in promise) ReferenceError: Cannot access 'folders' before initialization.

Steps To Reproduce

  • Create a new Laravel 12 project with any starterkit that includes Wayfinder;
  • Add a normal route like folders.show and a nested route like folders.folders.index:
Route::get('folders/{folder}', [FolderController::class, 'show'])->name('folders.show');
Route::get('folders/{folder}/folders', [FolderController::class, 'indexNested'])->name('folders.folders.index');
  • Create a Vue page or component that includes a route: import { show } from '@/routes/folders'
  • Visit the page: Uncaught (in promise) ReferenceError: Cannot access 'folders' before initialization

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions