tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
571 stars 23 forks source link

Support for Custom Page Extensions #74

Closed Elindorath closed 2 years ago

Elindorath commented 2 years ago

Hi there,

Using v0.1.0, I noticed that it doesn't seem to support Custom Page Extensions. Indeed, the generated nextjs-routes.d.ts file defines a route for every files found in the pages (or src/pages) directory, including non page ones.

I think it might be something you want to consider for #44.

Feel free to ask me anything that can help.

Thanks for this tool, Vercel should take inspiration from it!

tatethurston commented 2 years ago

Hey @Elindorath, thanks for the kind words. What files do you have in your pages directory?

Elindorath commented 2 years ago

Hi @tatethurston,

Thanks for the quick fix. Sadly, it was maybe a bit too quick 😉 .

In my project, I have set up pageExtensions to ['page.tsx', 'page.ts', 'api.ts']. This allow me to put test and style files aside of the file they are related (*.test.tsx and *.module.scss). I use the api.ts suffix specially for the api files, I have eslint rules to ensure it is used only in the right place. The structure looks like this:

src/pages/
├── auth/
│  ├── __snapshots__/
│  │  └── index.test.tsx.snap
│  ├── index.module.scss
│  ├── index.page.tsx
│  └── index.test.tsx
├── api/
│  ├── login/
│  │  ├── index.test.ts
│  │  └── index.api.ts
├── 404.page.tsx
├── _app.page.tsx
├── _app.scss
├── _error.page.tsx
└── index.page.tsx
tatethurston commented 2 years ago

Thanks @Elindorath, I overlooked multiple extensions. I've published a new release with your fix!