Skip to content

Commit

Permalink
Revert "does it work without entries.tsx and main.tsx?"
Browse files Browse the repository at this point in the history
This reverts commit 757ddc7.
  • Loading branch information
dai-shi committed Mar 8, 2024
1 parent 757ddc7 commit d621df2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/10_fs-router/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { fsRouter } from 'waku/router/server';

export default fsRouter(import.meta.url, loader);

function loader(dir: string, file: string) {
const p = file.replace(/\.\w+$/, '').split('/');
switch (p.length) {
case 1:
return import(`./${dir}/${p[0]}.tsx`);
case 2:
return import(`./${dir}/${p[0]}/${p[1]}.tsx`);
case 3:
return import(`./${dir}/${p[0]}/${p[1]}/${p[2]}.tsx`);
case 4:
return import(`./${dir}/${p[0]}/${p[1]}/${p[2]}/${p[3]}.tsx`);
case 5:
return import(`./${dir}/${p[0]}/${p[1]}/${p[2]}/${p[3]}/${p[5]}.tsx`);
default:
throw new Error('too deep');
}
}
19 changes: 19 additions & 0 deletions examples/10_fs-router/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StrictMode } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import { Router } from 'waku/router/client';

import { ErrorBoundary } from './components/ErrorBoundary.js';

const rootElement = (
<StrictMode>
<ErrorBoundary fallback={(error) => <h1>{String(error)}</h1>}>
<Router />
</ErrorBoundary>
</StrictMode>
);

if (document.body.dataset.hydrate) {
hydrateRoot(document.body, rootElement);
} else {
createRoot(document.body).render(rootElement);
}

0 comments on commit d621df2

Please sign in to comment.