Skip to content

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

@carl-sauter

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

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