T
TanStack2y ago
exotic-emerald

File-based routing bug or misconfig?

Tldr: I'm using file-based routing and the CLI sets all routes as children of rootRoute, which is unexpected Note the paths and getParentRoute calls in the generated file here:
Object.assign(IndexRoute.options, {
path: "/",
getParentRoute: () => rootRoute,
})

Object.assign(PatientsIndexRoute.options, {
path: "/patients/",
getParentRoute: () => rootRoute,
})

Object.assign(PatientsIdIndexRoute.options, {
path: "/patients/$id/",
getParentRoute: () => rootRoute,
})

Object.assign(PatientsIdReferenceNotesRoute.options, {
path: "/patients/$id/reference-notes",
getParentRoute: () => rootRoute,
})
Object.assign(IndexRoute.options, {
path: "/",
getParentRoute: () => rootRoute,
})

Object.assign(PatientsIndexRoute.options, {
path: "/patients/",
getParentRoute: () => rootRoute,
})

Object.assign(PatientsIdIndexRoute.options, {
path: "/patients/$id/",
getParentRoute: () => rootRoute,
})

Object.assign(PatientsIdReferenceNotesRoute.options, {
path: "/patients/$id/reference-notes",
getParentRoute: () => rootRoute,
})
Here's my config, full routeTree.gen.ts, and file structure: https://gist.github.com/Swizec/234a686fa18332cd488188f161c3b796
Gist
file-structure
GitHub Gist: instantly share code, notes, and snippets.
11 Replies
unwilling-turquoise
unwilling-turquoise2y ago
Dumb question. But are you on the latest version of the CLI?
exotic-emerald
exotic-emeraldOP2y ago
this is from beta.231 yesterday
unwilling-turquoise
unwilling-turquoise2y ago
Hmm. Have you tried cloning a file based example? If that works, then it’s a config issue, if it doesn’t, it’s a bug.
exotic-emerald
exotic-emeraldOP2y ago
I was starting from the file-based example you had up last week. Will compare with the new examples and get back to you
unwilling-turquoise
unwilling-turquoise2y ago
Sounds good Any movement here?
exotic-emerald
exotic-emeraldOP2y ago
Sorry I spent all week dealing with a *** security requirement instead 🫠 I’ll have an update on Monday
unwilling-turquoise
unwilling-turquoise2y ago
No worries or rush
exotic-emerald
exotic-emeraldOP2y ago
@Tanner Linsley I figured it out! I'm an idiot. Didn't realize that you needed to have a matching page.tsx file and /page folder to make this work. was trying all sorts of different magic names like _layout.tsx and __root.tsx
unwilling-turquoise
unwilling-turquoise2y ago
Oh man! 🤦 Let's get that added to the docs or something or if you have any other ideas on how to make that more clear
exotic-emerald
exotic-emeraldOP2y ago
I think if your example didn't use _layout I'd get it right away. _layout looks like a magic name because of other frameworks nextjs specifically uses a layout.tsx placed anywhere in your directory tree as the layout for all subpages
unwilling-turquoise
unwilling-turquoise2y ago
Ah I see. I can change that easy

Did you find this page helpful?