Skip to content

Commit

Permalink
feat: new create pages to use new defineRouter (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersayshi authored Nov 10, 2024
1 parent c294b87 commit ae703c1
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 82 deletions.
1 change: 1 addition & 0 deletions examples/21_create-pages/src/components/NestedBazPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Baz = () => (
<div>
<h2>Nested</h2>
<h3>Baz</h3>
<p>{new Date().toISOString()}</p>
</div>
);

Expand Down
154 changes: 77 additions & 77 deletions examples/21_create-pages/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPages } from 'waku';
import { new_createPages } from 'waku';
import type { PathsForPages } from 'waku/router';

import FooPage from './components/FooPage';
Expand All @@ -9,93 +9,93 @@ import NestedBazPage from './components/NestedBazPage';
import NestedQuxPage from './components/NestedQuxPage';
import Root from './components/Root';

const pages = createPages(async ({ createPage, createLayout, createRoot }) => [
createRoot({
render: 'static',
component: Root,
}),
const pages = new_createPages(
async ({ createPage, createLayout, createRoot }) => [
createRoot({
render: 'static',
component: Root,
}),

createLayout({
render: 'static',
path: '/',
component: HomeLayout,
}),
createLayout({
render: 'static',
path: '/',
component: HomeLayout,
}),

createPage({
render: 'static',
// render: 'dynamic',
path: '/',
component: HomePage,
}),
createPage({
render: 'static',
path: '/',
component: HomePage,
}),

createPage({
render: 'static',
// render: 'dynamic',
path: '/foo',
component: FooPage,
}),
createPage({
render: 'static',
path: '/foo',
component: FooPage,
}),

createPage({
render: 'static',
path: '/bar',
component: BarPage,
}),
createPage({
render: 'static',
path: '/bar',
component: BarPage,
}),

createPage({
render: 'dynamic',
path: '/baz',
// Inline component is also possible.
component: () => <h2>Dynamic: Baz</h2>,
}),
createPage({
render: 'dynamic',
path: '/baz',
// Inline component is also possible.
component: () => <h2>Dynamic: Baz</h2>,
}),

createPage({
render: 'static',
path: '/nested/baz',
component: NestedBazPage,
}),
createPage({
render: 'dynamic',
path: '/nested/baz',
component: NestedBazPage,
}),

createPage({
render: 'static',
path: '/nested/qux',
component: NestedQuxPage,
}),
createPage({
render: 'static',
path: '/nested/qux',
component: NestedQuxPage,
}),

createPage({
render: 'static',
path: '/nested/[id]',
staticPaths: ['foo', 'bar'],
component: ({ id }) => (
<>
<h2>Nested</h2>
<h3>Static: {id}</h3>
</>
),
}),
createPage({
render: 'static',
path: '/nested/[id]',
staticPaths: ['foo', 'bar'],
component: ({ id }) => (
<>
<h2>Nested</h2>
<h3>Static: {id}</h3>
</>
),
}),

createPage({
render: 'dynamic',
path: '/nested/[id]',
component: ({ id }) => (
<>
<h2>Nested</h2>
<h3>Dynamic: {id}</h3>
</>
),
}),
createPage({
render: 'dynamic',
path: '/nested/[id]',
component: ({ id }) => (
<>
<h2>Nested</h2>
<h3>Dynamic: {id}</h3>
</>
),
}),

createPage({
render: 'dynamic',
path: '/any/[...all]',
component: ({ all }) => <h2>Catch-all: {all.join('/')}</h2>,
}),
createPage({
render: 'dynamic',
path: '/any/[...all]',
component: ({ all }) => <h2>Catch-all: {all.join('/')}</h2>,
}),

// Custom Not Found page
createPage({
render: 'static',
path: '/404',
component: () => <h2>Not Found</h2>,
}),
]);
// Custom Not Found page
createPage({
render: 'static',
path: '/404',
component: () => <h2>Not Found</h2>,
}),
],
);

declare module 'waku/router' {
interface RouteConfig {
Expand Down
4 changes: 2 additions & 2 deletions examples/21_create-pages/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StrictMode } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import { Router } from 'waku/router/client';
import { NewRouter } from 'waku/router/client';

const rootElement = (
<StrictMode>
<Router />
<NewRouter />
</StrictMode>
);

Expand Down
2 changes: 1 addition & 1 deletion packages/waku/src/main.react-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Link, useRouter_UNSTABLE } from 'waku/router/client';

export { createPages } from 'waku/router/server';
export { createPages, new_createPages } from 'waku/router/server';

export { getEnv } from 'waku/server';
7 changes: 7 additions & 0 deletions packages/waku/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { Link, useRouter_UNSTABLE } from 'waku/router/client';

import type {
createPages as createPagesType,
new_createPages as new_createPagesType,
getEnv as getEnvType,
} from './main.react-server.js';

Expand All @@ -11,6 +12,12 @@ export const createPages: typeof createPagesType = () => {
);
};

export const new_createPages: typeof new_createPagesType = () => {
throw new Error(
'`new_createPagesType` is only available in react-server environment',
);
};

export const getEnv: typeof getEnvType = () => {
throw new Error('`getEnv` is only available in react-server environment');
};
Loading

0 comments on commit ae703c1

Please sign in to comment.