TanStackT
TanStackโ€ข7mo agoโ€ข
2 replies
clean-aquamarine

How to emulate Next.js app router constraints

Unlike probably most people here, I like next's directory-based routing model and hate remix's file-based routing mode, whether with flat-routes or not

Unfortunately I don't like the rest of Next, so I was wondering if there's any way to emulate its routing using tanstack router's router settings. Basically what I want is:
๐Ÿ“ src/routes/
โ”œโ”€โ”€ ๐Ÿ“„ page.tsx ('/' route file)
โ”œโ”€โ”€ ๐Ÿ“„ a.tsx (ignored)
โ”œโ”€โ”€ ๐Ÿ“„ __root.tsx (root route)
โ”œโ”€โ”€ ๐Ÿ“ blog/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ layout.tsx ('/blog/*' route layout)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ page.tsx ('/blog/' route file)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ b.tsx (ignored)
โ”‚   โ””โ”€โ”€ ๐Ÿ“ $slug/
โ”‚       โ””โ”€โ”€ ๐Ÿ“„ page.tsx ('/blog/$slug' route file)
โ””โ”€โ”€ ๐Ÿ“ about/
    โ””โ”€โ”€ ๐Ÿ“„ page.tsx ('/about/' route file)
    โ””โ”€โ”€ ๐Ÿ“ components/
        โ””โ”€โ”€ ๐Ÿ“„ c.tsx (ignored)

I tried this configuration, but it ignores directories with a name that fall into the pattern:
tanstackRouter({
    autoCodeSplitting: true,
    routeFileIgnorePrefix: '',
    routeFileIgnorePattern: '^(?!.*(?:page|layout|__root)\\.tsx$).*$',
    routeToken: 'layout',
    indexToken: 'page',
})
Was this page helpful?