Skip to content

Commit 3826f8f

Browse files
committed
fix(routes): support layout and _layout
1 parent 6d7b035 commit 3826f8f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/routes/src/PagesService.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function resolveRoutePath(basePath: string, relFilePath: string) {
5757
.replace(/^(\/index){2}$/, '') // remove '/index/index'
5858
.replace(/\/index$/, '') // remove '/index'
5959
.replace(/\/README$/i, '') // remove '/README'
60-
.replace(/\/_layout$/, '') // remove '/_layout'
60+
.replace(/\/_?layout$/, '') // remove '/_layout' and '/layout'
6161
.replace(/\/404$/, '/*') // transform '/404' to '/*' so this route acts like a catch-all for URLs that we don't have explicit routes for
6262
.replace(/\/\[\.{3}.*?\]$/, '/*') // transform '/post/[...all]' to '/post/*'
6363
.replace(/\/\[(.*?)\]/g, '/:$1'); // transform 'user/[id]' to 'user/:id'
@@ -68,7 +68,8 @@ function resolveRoutePath(basePath: string, relFilePath: string) {
6868
}
6969

7070
function isLayoutFile(filePath: string) {
71-
return path.basename(filePath, path.extname(filePath)) === '_layout';
71+
const name = path.basename(filePath, path.extname(filePath));
72+
return name === '_layout' || name === 'layout';
7273
}
7374

7475
function is404File(filePath: string) {
@@ -92,7 +93,10 @@ export class PagesService extends EventEmitter {
9293
return (this._startPromise = Promise.all(
9394
this.config.pages.config.map(
9495
async ({ basePath, dir, pattern, ignore }) => {
95-
pattern = ['**/_layout.{js,jsx,ts,tsx,md,mdx}', ...toArray(pattern)];
96+
pattern = [
97+
'**/{_layout,layout}.{js,jsx,ts,tsx,md,mdx}',
98+
...toArray(pattern),
99+
];
96100
ignore = toArray(ignore);
97101

98102
const relFilePaths = fg.sync(pattern, { cwd: dir, ignore });

0 commit comments

Comments
 (0)