Skip to content

Commit e93d14b

Browse files
authored
feat(fs-router): allow _components & _hooks in the pages folder (#1222)
ignores any files inside `_components` and `_hooks` folders inside `src/pages`. Previously, these would be considered to be pages but they will now be ignored. This allows easier co-location of components with their pages. resolves #1220 --------- Co-authored-by: Tyler <[email protected]>
1 parent cf58f61 commit e93d14b

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

e2e/fixtures/fs-router/src/pages/bar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Counter } from '../components/Counter.js';
1+
import { Counter } from './_components/Counter.js';
22

33
const Bar = () => (
44
<div>

e2e/fixtures/fs-router/src/pages/foo/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Counter } from '../../components/Counter.js';
1+
import { Counter } from '../_components/Counter.js';
22

33
const Foo = () => (
44
<div>

e2e/fs-router.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,10 @@ for (const mode of ['DEV', 'PRD'] as const) {
7676
expect(res.status).toBe(200);
7777
expect(await res.text()).toBe('POST Hello from API! from the test!');
7878
});
79+
80+
test('_components', async ({ page }) => {
81+
await page.goto(`http://localhost:${port}/_components/Counter`);
82+
await expect(page.getByText('404 Not Found')).toBeVisible();
83+
});
7984
});
8085
}

packages/waku/src/router/fs-router.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export function unstable_fsRouter(
6868
.replace(/\.\w+$/, '')
6969
.split('/')
7070
.filter(Boolean);
71+
if (pathItems.includes('_components') || pathItems.includes('_hooks')) {
72+
continue;
73+
}
7174
const path =
7275
'/' +
7376
(['_layout', 'index', '_root'].includes(pathItems.at(-1)!)

0 commit comments

Comments
 (0)