Skip to content

routesDirectory treated differently in the vite-plugin and the router-generator #1240

Closed

Description

@carl-sauter

Describe the bug

I noticed that vite-plugin and the router generator use a different root when handling the routesDirectory from the router config.

Consider my vite root directory in /src/renderer. When I specify ./src/renderer/src/routes as my routesDirectory the vite-plugin is joining the path together with vite.root, when handling a hot update. This results in /src/renderer/src/renderer/src/routes.

On the other hand the router-generator is joining the path with the projects root directory. This results in /src/renderer/src/routes, which is correct. The problem is now, that either the vite plugin is watching the wrong directory or the generator can't find the right files.

Your Example Website or App

https://stackblitz.com/edit/github-k8oxxb

Steps to Reproduce the Bug or Issue

  1. Create a vite project with the vite config file at the project root.
  2. Move the index.html and the src directory to ./ui
  3. Specify root as ./ui in the vite config
  4. Setup TanstackRouter with the vite plugin and routesDirectory: './ui'

Expected behavior

I expect that the routes gets processed properly and the vite plugin is detecting changes. The outcome is, that the routes gets generated at vite startup, but not when I do changes to the files.

Screenshots or Videos

No response

Platform

Not platform specific

Additional context

See packages/router-vite-plugin/src/index.ts at line 23
and packages/router-generator/src/generator.ts at line 136

Activity

  1. linusrush commented on Mar 4, 2024

    @linusrush

    Ran into the same problem while using electron-vite.
    The vite config is in project root, but ui root is in "src/renderer".

    The routesDirectory from router config is handled differently in vite-plugin and router-generator.

  2. carl-sauter commented on Mar 12, 2024

    @carl-sauter
    ContributorAuthor

    Any updates?

  3. schiller-manuel commented on Mar 13, 2024

    @schiller-manuel
    Collaborator

    can you please provide a complete example project where this issue is happening?

  4. carl-sauter commented on Mar 13, 2024

    @carl-sauter
    ContributorAuthor

    https://stackblitz.com/edit/github-k8oxxb

    You will notice, that the routes get generated on vite startup, but no changes to the files are recognized.
    If you change the routesDirectory to .src/routes changes will be recognized, but the generator fails, cause it looks at the wrong path for the files.

  5. dmitrymaslov99 commented on Apr 9, 2024

    @dmitrymaslov99

    Any updates?

  6. carl-sauter commented on Apr 9, 2024

    @carl-sauter
    ContributorAuthor

    As you can see this was closed & the merge request was merged. So it should work now

  7. dmitrymaslov99 commented on Apr 9, 2024

    @dmitrymaslov99

    It still doesn't work. n electron.vite.config.mjs if you specify the relative path of the settings:
    TanStackRouterVite({ routesDirectory: "./src/renderer/src/routes", generatedRouteTree: "./src/renderer/src/routeTree.gen.ts", }),
    This also does not work when updating/adding/deleting files. But it works on startup. If you specify an absolute path, everything works. But I'm not sure if this is a good approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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