Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/vinext/src/routing/pages-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ async function scanPageRoutes(
"**/*",
pagesDir,
matcher.extensions,
(name: string) => name === "api" || name.startsWith("_"),
(name: string) => name.startsWith("_"),
)) {
// Ignore top-level pages/api/* only (nested */api/* directories are valid page routes)
if (file === "api" || file.startsWith(`api${path.sep}`)) {
continue;
}

const route = fileToRoute(file, pagesDir, matcher);
if (route) routes.push(route);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/pages-basic/pages/blog/api/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function BlogApiPage() {
return <div>Blog API page route</div>;
}
9 changes: 9 additions & 0 deletions tests/routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ describe("pagesRouter - route discovery", () => {
expect(patterns).not.toContain("/_document");
expect(patterns).not.toContain("/_error");
});

it("keeps nested api directories as page routes", async () => {
const routes = await pagesRouter(FIXTURE_DIR);

const nestedApiRoute = routes.find((r) => r.pattern === "/blog/api");
expect(nestedApiRoute).toBeDefined();
expect(nestedApiRoute!.filePath).toContain(path.join("blog", "api", "index.tsx"));
});

});

describe("matchRoute - URL matching", () => {
Expand Down