@evjs/create-app 0.1.11 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +5 -1
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +122 -98
  4. package/package.json +9 -1
  5. package/templates/api-routes/README.md +2 -2
  6. package/templates/api-routes/package.json +4 -4
  7. package/templates/api-routes/src/{pages/__root.tsx → layout/index.tsx} +3 -5
  8. package/templates/api-routes/src/pages/{home.tsx → index.tsx} +1 -9
  9. package/templates/basic/README.md +3 -5
  10. package/templates/basic/package.json +4 -4
  11. package/templates/basic/src/layout/index.tsx +27 -0
  12. package/templates/basic/src/pages/about.tsx +17 -0
  13. package/templates/basic/src/pages/index.tsx +100 -0
  14. package/templates/basic/src/pages/search.tsx +58 -0
  15. package/templates/basic/src/pages/users/$userId.tsx +31 -0
  16. package/templates/complex-routing/README.md +6 -7
  17. package/templates/complex-routing/package.json +4 -4
  18. package/templates/complex-routing/src/api/data.server.ts +1 -1
  19. package/templates/complex-routing/src/{pages/__root.tsx → layout/index.tsx} +4 -5
  20. package/templates/complex-routing/src/pages/dashboard.tsx +2 -23
  21. package/templates/complex-routing/src/pages/index.tsx +31 -0
  22. package/templates/complex-routing/src/pages/old-blog.tsx +9 -0
  23. package/templates/complex-routing/src/pages/posts/$postId.tsx +39 -0
  24. package/templates/complex-routing/src/pages/posts/index.tsx +21 -88
  25. package/templates/complex-routing/src/pages/search.tsx +10 -13
  26. package/templates/complex-routing/src/pages/users/$username.tsx +21 -0
  27. package/templates/custom-ws-transport/README.md +2 -2
  28. package/templates/custom-ws-transport/package.json +4 -4
  29. package/templates/custom-ws-transport/src/{pages/__root.tsx → layout/index.tsx} +4 -5
  30. package/templates/custom-ws-transport/src/pages/{home.tsx → index.tsx} +2 -9
  31. package/templates/mpa/README.md +8 -6
  32. package/templates/mpa/ev.config.ts +2 -3
  33. package/templates/mpa/package.json +2 -2
  34. package/templates/mpa/src/pages/about.tsx +13 -0
  35. package/templates/mpa/src/pages/home.tsx +13 -0
  36. package/templates/plugin-authoring/README.md +2 -2
  37. package/templates/plugin-authoring/ev.config.ts +11 -12
  38. package/templates/plugin-authoring/package.json +5 -4
  39. package/templates/plugin-authoring/src/layout/index.tsx +9 -0
  40. package/templates/plugin-authoring/src/pages/{home.tsx → index.tsx} +2 -9
  41. package/templates/with-sqlite/README.md +2 -1
  42. package/templates/with-sqlite/package.json +4 -4
  43. package/templates/with-sqlite/src/api/db.server.ts +103 -23
  44. package/templates/with-sqlite/src/{pages/__root.tsx → layout/index.tsx} +4 -5
  45. package/templates/with-sqlite/src/pages/{home.tsx → index.tsx} +1 -9
  46. package/templates/with-tailwind/ev.config.ts +3 -1
  47. package/templates/with-tailwind/package.json +3 -4
  48. package/templates/with-tailwind/src/{pages/__root.tsx → layout/index.tsx} +4 -7
  49. package/templates/with-tailwind/src/pages/{home.tsx → index.tsx} +17 -31
  50. package/templates/with-trpc/README.md +2 -1
  51. package/templates/with-trpc/package.json +4 -4
  52. package/templates/with-trpc/src/{pages/__root.tsx → layout/index.tsx} +3 -7
  53. package/templates/with-trpc/src/pages/{home.tsx → index.tsx} +2 -9
  54. package/templates/api-routes/src/main.tsx +0 -15
  55. package/templates/basic/src/main.tsx +0 -37
  56. package/templates/basic/src/pages/__root.tsx +0 -49
  57. package/templates/basic/src/pages/home.tsx +0 -207
  58. package/templates/complex-routing/src/main.tsx +0 -29
  59. package/templates/complex-routing/src/pages/catch.tsx +0 -26
  60. package/templates/complex-routing/src/pages/home.tsx +0 -35
  61. package/templates/complex-routing/src/pages/user.tsx +0 -28
  62. package/templates/custom-ws-transport/src/main.tsx +0 -15
  63. package/templates/mpa/src/about/main.tsx +0 -23
  64. package/templates/mpa/src/home/main.tsx +0 -23
  65. package/templates/plugin-authoring/src/main.tsx +0 -15
  66. package/templates/plugin-authoring/src/pages/__root.tsx +0 -13
  67. package/templates/with-sqlite/src/main.tsx +0 -15
  68. package/templates/with-tailwind/src/main.tsx +0 -15
  69. package/templates/with-trpc/src/main.tsx +0 -15
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export default function Root({ children }: { children?: ReactNode }) {
4
+ return (
5
+ <div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
6
+ {children}
7
+ </div>
8
+ );
9
+ }
@@ -1,8 +1,7 @@
1
- import { createRoute, useQuery } from "@evjs/client";
1
+ import { useQuery } from "@evjs/client";
2
2
  import { getPluginMessage } from "../api/plugin.server";
3
- import { rootRoute } from "./__root";
4
3
 
5
- function Home() {
4
+ export default function Home() {
6
5
  const { data, isLoading } = useQuery(getPluginMessage);
7
6
 
8
7
  return (
@@ -28,9 +27,3 @@ function Home() {
28
27
  </div>
29
28
  );
30
29
  }
31
-
32
- export const homeRoute = createRoute({
33
- getParentRoute: () => rootRoute,
34
- path: "/",
35
- component: Home,
36
- });
@@ -12,7 +12,8 @@ npm run dev
12
12
 
13
13
  | File | Purpose |
14
14
  |------|---------|
15
- | `src/routes.tsx` | Users list + todo management UI |
15
+ | `src/layout/index.tsx` | SPA root layout |
16
+ | `src/pages/index.tsx` | Users list + todo management UI |
16
17
  | `src/api/db.server.ts` | SQLite database setup |
17
18
  | `src/api/users.server.ts` | User CRUD (create, delete, getUsers, getUser) |
18
19
  | `src/api/todos.server.ts` | Todo CRUD (create, toggle, delete) |
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-sqlite",
3
- "version": "0.1.11",
3
+ "version": "0.2.1",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -8,14 +8,14 @@
8
8
  "check-types": "tsc --noEmit"
9
9
  },
10
10
  "dependencies": {
11
+ "@evjs/client": "*",
12
+ "@evjs/ev": "*",
13
+ "@evjs/server": "*",
11
14
  "react": "^19.2.4",
12
15
  "react-dom": "^19.2.4"
13
16
  },
14
17
  "devDependencies": {
15
18
  "@evjs/cli": "*",
16
- "@evjs/client": "*",
17
- "@evjs/ev": "*",
18
- "@evjs/server": "*",
19
19
  "@types/react": "^19.1.8",
20
20
  "@types/react-dom": "^19.1.8",
21
21
  "typescript": "^6.0.2"
@@ -1,7 +1,7 @@
1
1
  "use server";
2
2
 
3
3
  import path from "node:path";
4
- import { DatabaseSync } from "node:sqlite";
4
+ import { DatabaseSync, type SQLOutputValue } from "node:sqlite";
5
5
  import { ServerError } from "@evjs/server";
6
6
 
7
7
  /**
@@ -34,10 +34,12 @@ db.exec(`
34
34
  `);
35
35
 
36
36
  // Seed with sample data if empty
37
- const countRow = db.prepare("SELECT COUNT(*) as count FROM users").get() as {
38
- count: number;
39
- };
40
- if (countRow.count === 0) {
37
+ const userCount = readNumber(
38
+ db.prepare("SELECT COUNT(*) as count FROM users").get(),
39
+ "count",
40
+ "users count",
41
+ );
42
+ if (userCount === 0) {
41
43
  const insertUser = db.prepare(
42
44
  "INSERT INTO users (name, email) VALUES (?, ?)",
43
45
  );
@@ -69,14 +71,15 @@ export interface User {
69
71
  export async function getUsers(): Promise<User[]> {
70
72
  return db
71
73
  .prepare("SELECT * FROM users ORDER BY id")
72
- .all() as unknown as User[];
74
+ .all()
75
+ .map((row) => readUser(row));
73
76
  }
74
77
 
75
78
  /** Get a single user by ID. */
76
79
  export async function getUser(id: number): Promise<User> {
77
- const user = db.prepare("SELECT * FROM users WHERE id = ?").get(id) as
78
- | User
79
- | undefined;
80
+ const user = readOptionalUser(
81
+ db.prepare("SELECT * FROM users WHERE id = ?").get(id),
82
+ );
80
83
  if (!user) {
81
84
  throw new ServerError("User not found", { status: 404, data: { id } });
82
85
  }
@@ -93,10 +96,12 @@ export async function createUser(data: {
93
96
  data.name,
94
97
  data.email,
95
98
  );
96
- const lastId = (
97
- db.prepare("SELECT last_insert_rowid() as id").get() as { id: number }
98
- ).id;
99
- return (await getUser(lastId)) as User;
99
+ const lastId = readNumber(
100
+ db.prepare("SELECT last_insert_rowid() as id").get(),
101
+ "id",
102
+ "last inserted user id",
103
+ );
104
+ return await getUser(lastId);
100
105
  } catch (e: unknown) {
101
106
  if (e instanceof Error && e.message.includes("UNIQUE")) {
102
107
  throw new ServerError("Email already exists", {
@@ -130,7 +135,8 @@ export interface Todo {
130
135
  export async function getTodos(userId: number): Promise<Todo[]> {
131
136
  return db
132
137
  .prepare("SELECT * FROM todos WHERE user_id = ? ORDER BY id")
133
- .all(userId) as unknown as Todo[];
138
+ .all(userId)
139
+ .map((row) => readTodo(row));
134
140
  }
135
141
 
136
142
  /** Create a todo for a user. */
@@ -144,21 +150,24 @@ export async function createTodo(data: {
144
150
  data.userId,
145
151
  data.title,
146
152
  );
147
- const lastId = (
148
- db.prepare("SELECT last_insert_rowid() as id").get() as { id: number }
149
- ).id;
153
+ const lastId = readNumber(
154
+ db.prepare("SELECT last_insert_rowid() as id").get(),
155
+ "id",
156
+ "last inserted todo id",
157
+ );
150
158
 
151
- return db
152
- .prepare("SELECT * FROM todos WHERE id = ?")
153
- .get(lastId) as unknown as Todo;
159
+ return readTodo(
160
+ db.prepare("SELECT * FROM todos WHERE id = ?").get(lastId),
161
+ "created todo",
162
+ );
154
163
  }
155
164
 
156
165
  /** Toggle a todo's completed status. */
157
166
  export async function toggleTodo(id: number): Promise<Todo> {
158
167
  db.prepare("UPDATE todos SET completed = NOT completed WHERE id = ?").run(id);
159
- const todo = db.prepare("SELECT * FROM todos WHERE id = ?").get(id) as
160
- | Todo
161
- | undefined;
168
+ const todo = readOptionalTodo(
169
+ db.prepare("SELECT * FROM todos WHERE id = ?").get(id),
170
+ );
162
171
  if (!todo) {
163
172
  throw new ServerError("Todo not found", { status: 404, data: { id } });
164
173
  }
@@ -172,3 +181,74 @@ export async function deleteTodo(id: number): Promise<void> {
172
181
  throw new ServerError("Todo not found", { status: 404, data: { id } });
173
182
  }
174
183
  }
184
+
185
+ type SqlRow = Record<string, SQLOutputValue>;
186
+
187
+ function readUser(row: SqlRow | undefined, source = "user row"): User {
188
+ if (!row) throw new Error(`[with-sqlite] Missing ${source}.`);
189
+ return {
190
+ id: readNumber(row, "id", source),
191
+ name: readString(row, "name", source),
192
+ email: readString(row, "email", source),
193
+ created_at: readString(row, "created_at", source),
194
+ };
195
+ }
196
+
197
+ function readOptionalUser(row: SqlRow | undefined): User | undefined {
198
+ return row ? readUser(row) : undefined;
199
+ }
200
+
201
+ function readTodo(row: SqlRow | undefined, source = "todo row"): Todo {
202
+ if (!row) throw new Error(`[with-sqlite] Missing ${source}.`);
203
+ return {
204
+ id: readNumber(row, "id", source),
205
+ user_id: readNumber(row, "user_id", source),
206
+ title: readString(row, "title", source),
207
+ completed: readNumber(row, "completed", source),
208
+ created_at: readString(row, "created_at", source),
209
+ };
210
+ }
211
+
212
+ function readOptionalTodo(row: SqlRow | undefined): Todo | undefined {
213
+ return row ? readTodo(row) : undefined;
214
+ }
215
+
216
+ function readNumber(
217
+ row: SqlRow | undefined,
218
+ key: string,
219
+ source: string,
220
+ ): number {
221
+ const value = readValue(row, key, source);
222
+ if (typeof value === "number") return value;
223
+ throw createColumnError(source, key, "number", value);
224
+ }
225
+
226
+ function readString(
227
+ row: SqlRow | undefined,
228
+ key: string,
229
+ source: string,
230
+ ): string {
231
+ const value = readValue(row, key, source);
232
+ if (typeof value === "string") return value;
233
+ throw createColumnError(source, key, "string", value);
234
+ }
235
+
236
+ function readValue(
237
+ row: SqlRow | undefined,
238
+ key: string,
239
+ source: string,
240
+ ): SQLOutputValue | undefined {
241
+ if (!row) throw new Error(`[with-sqlite] Missing ${source}.`);
242
+ return row[key];
243
+ }
244
+
245
+ function createColumnError(
246
+ source: string,
247
+ key: string,
248
+ expected: string,
249
+ value: SQLOutputValue | undefined,
250
+ ): Error {
251
+ return new Error(
252
+ `[with-sqlite] Expected ${source}.${key} to be a ${expected}, got ${typeof value}.`,
253
+ );
254
+ }
@@ -1,6 +1,7 @@
1
- import { createAppRootRoute, Link, Outlet } from "@evjs/client";
1
+ import { Link } from "@evjs/client";
2
+ import type { ReactNode } from "react";
2
3
 
3
- function Root() {
4
+ export default function Root({ children }: { children?: ReactNode }) {
4
5
  return (
5
6
  <div
6
7
  style={{
@@ -27,9 +28,7 @@ function Root() {
27
28
  Users
28
29
  </Link>
29
30
  </nav>
30
- <Outlet />
31
+ {children}
31
32
  </div>
32
33
  );
33
34
  }
34
-
35
- export const rootRoute = createAppRootRoute({ component: Root });
@@ -1,5 +1,4 @@
1
1
  import {
2
- createRoute,
3
2
  getFnQueryKey,
4
3
  useMutation,
5
4
  useQuery,
@@ -16,11 +15,10 @@ import {
16
15
  getUsers,
17
16
  toggleTodo,
18
17
  } from "../api/db.server";
19
- import { rootRoute } from "./__root";
20
18
 
21
19
  // ── Users Page ──
22
20
 
23
- function UsersPage() {
21
+ export default function UsersPage() {
24
22
  const [name, setName] = useState("");
25
23
  const [email, setEmail] = useState("");
26
24
  const [selectedUserId, setSelectedUserId] = useState<number | null>(null);
@@ -263,9 +261,3 @@ function TodosSection({ userId }: { userId: number }) {
263
261
  </div>
264
262
  );
265
263
  }
266
-
267
- export const usersRoute = createRoute({
268
- getParentRoute: () => rootRoute,
269
- path: "/",
270
- component: UsersPage,
271
- });
@@ -8,4 +8,6 @@ import { defineConfig } from "@evjs/ev";
8
8
  * `evjs` automatically applies `postcss-loader` alongside `css-loader`.
9
9
  * No custom loaders or `bundler` hooks are needed!
10
10
  */
11
- export default defineConfig({});
11
+ export default defineConfig({
12
+ server: false,
13
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-tailwind",
3
- "version": "0.1.11",
3
+ "version": "0.2.1",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -8,15 +8,14 @@
8
8
  "check-types": "tsc --noEmit"
9
9
  },
10
10
  "dependencies": {
11
+ "@evjs/client": "*",
12
+ "@evjs/ev": "*",
11
13
  "@tailwindcss/typography": "^0.5.19",
12
14
  "react": "^19.2.4",
13
15
  "react-dom": "^19.2.4"
14
16
  },
15
17
  "devDependencies": {
16
18
  "@evjs/cli": "*",
17
- "@evjs/client": "*",
18
- "@evjs/ev": "*",
19
- "@evjs/server": "*",
20
19
  "@tailwindcss/postcss": "^4.1.10",
21
20
  "@types/react": "^19.1.8",
22
21
  "@types/react-dom": "^19.1.8",
@@ -1,7 +1,8 @@
1
- import { createRootRoute, Link, Outlet } from "@evjs/client";
1
+ import { Link } from "@evjs/client";
2
+ import type { ReactNode } from "react";
2
3
  import "../styles.css";
3
4
 
4
- function Root() {
5
+ export default function Root({ children }: { children?: ReactNode }) {
5
6
  return (
6
7
  <div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white">
7
8
  <nav className="border-b border-white/10 backdrop-blur-sm bg-white/5">
@@ -20,11 +21,7 @@ function Root() {
20
21
  </Link>
21
22
  </div>
22
23
  </nav>
23
- <Outlet />
24
+ {children}
24
25
  </div>
25
26
  );
26
27
  }
27
-
28
- export const rootRoute = createRootRoute({
29
- component: Root,
30
- });
@@ -1,12 +1,6 @@
1
- import { createRoute } from "@evjs/client";
2
- import { rootRoute } from "./__root";
3
-
4
- export const homeRoute = createRoute({
5
- getParentRoute: () => rootRoute,
6
- path: "/",
7
- component: () => (
1
+ export default function HomePage() {
2
+ return (
8
3
  <main className="max-w-4xl mx-auto px-6 py-16">
9
- {/* Hero */}
10
4
  <div className="text-center mb-16">
11
5
  <h1
12
6
  className="text-5xl font-extrabold tracking-tight bg-gradient-to-r from-blue-400 via-violet-400 to-fuchsia-400 bg-clip-text text-transparent"
@@ -18,46 +12,43 @@ export const homeRoute = createRoute({
18
12
  className="mt-4 text-lg text-slate-400 max-w-xl mx-auto"
19
13
  data-testid="subtitle"
20
14
  >
21
- Styled with Tailwind CSS v4 via the evjs plugin system — no webpack
22
- config needed.
15
+ Styled with Tailwind CSS v4 via evjs page routes, no webpack config
16
+ needed.
23
17
  </p>
24
18
  </div>
25
19
 
26
- {/* Feature cards */}
27
20
  <div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-16">
28
21
  <div className="rounded-xl border border-white/10 bg-white/5 backdrop-blur-sm p-6 hover:bg-white/10 transition-colors">
29
- <div className="text-3xl mb-3">🔌</div>
30
- <h3 className="font-semibold text-white mb-1">Plugin Loaders</h3>
22
+ <div className="text-3xl mb-3">Plugin</div>
23
+ <h3 className="font-semibold text-white mb-1">PostCSS Pipeline</h3>
31
24
  <p className="text-sm text-slate-400">
32
- Declare loaders in ev.config.ts. The framework handles the rest.
25
+ The framework applies the local PostCSS and Tailwind setup.
33
26
  </p>
34
27
  </div>
35
28
 
36
29
  <div className="rounded-xl border border-white/10 bg-white/5 backdrop-blur-sm p-6 hover:bg-white/10 transition-colors">
37
- <div className="text-3xl mb-3">🎨</div>
30
+ <div className="text-3xl mb-3">CSS</div>
38
31
  <h3 className="font-semibold text-white mb-1">Tailwind CSS v4</h3>
39
32
  <p className="text-sm text-slate-400">
40
- Full utility-first styling with zero configuration overhead.
33
+ Full utility-first styling with a page module as the route entry.
41
34
  </p>
42
35
  </div>
43
36
 
44
37
  <div className="rounded-xl border border-white/10 bg-white/5 backdrop-blur-sm p-6 hover:bg-white/10 transition-colors">
45
- <div className="text-3xl mb-3">⚡</div>
46
- <h3 className="font-semibold text-white mb-1">Zero Config</h3>
38
+ <div className="text-3xl mb-3">Zero</div>
39
+ <h3 className="font-semibold text-white mb-1">Page Routes</h3>
47
40
  <p className="text-sm text-slate-400">
48
- evjs works out of the box. Plugins extend it cleanly.
41
+ The route path is derived from <code>src/pages/index.tsx</code>.
49
42
  </p>
50
43
  </div>
51
44
  </div>
52
45
 
53
- {/* Typography plugin demo */}
54
46
  <div className="rounded-xl border border-white/10 bg-white/5 backdrop-blur-sm p-8 mb-16">
55
47
  <div className="prose prose-invert max-w-none" data-testid="prose">
56
48
  <h2>Typography Plugin</h2>
57
49
  <p>
58
- This section uses <code>@tailwindcss/typography</code> via the{" "}
59
- <code>prose</code> class. It automatically styles headings,
60
- paragraphs, code blocks, lists, and more with beautiful defaults.
50
+ This section uses <code>@tailwindcss/typography</code> through the{" "}
51
+ <code>prose</code> class.
61
52
  </p>
62
53
  <ul>
63
54
  <li>Automatic heading styles</li>
@@ -69,17 +60,12 @@ export const homeRoute = createRoute({
69
60
  </div>
70
61
  </div>
71
62
 
72
- {/* Config preview */}
73
63
  <div className="rounded-xl border border-white/10 bg-white/5 backdrop-blur-sm p-6">
74
64
  <h2 className="text-lg font-semibold text-white mb-4">ev.config.ts</h2>
75
65
  <pre className="text-sm text-slate-300 bg-black/30 rounded-lg p-4 overflow-x-auto">
76
- <code>{`export default defineConfig({
77
- client: {
78
- plugins: [tailwind()],
79
- },
80
- });`}</code>
66
+ <code>{`export default defineConfig({});`}</code>
81
67
  </pre>
82
68
  </div>
83
69
  </main>
84
- ),
85
- });
70
+ );
71
+ }
@@ -12,7 +12,8 @@ npm run dev
12
12
 
13
13
  | File | Purpose |
14
14
  |------|---------|
15
- | `src/routes.tsx` | UI consuming both tRPC and evjs APIs |
15
+ | `src/layout/index.tsx` | SPA root layout |
16
+ | `src/pages/index.tsx` | UI consuming both tRPC and evjs APIs |
16
17
  | `src/api/trpc.server.ts` | tRPC router exposed as server function |
17
18
  | `src/api/users.server.ts` | Standard evjs server functions |
18
19
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-trpc",
3
- "version": "0.1.11",
3
+ "version": "0.2.1",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -8,6 +8,9 @@
8
8
  "check-types": "tsc --noEmit"
9
9
  },
10
10
  "dependencies": {
11
+ "@evjs/client": "*",
12
+ "@evjs/ev": "*",
13
+ "@evjs/server": "*",
11
14
  "@trpc/client": "^11.0.0-rc.825",
12
15
  "@trpc/react-query": "^11.0.0-rc.825",
13
16
  "@trpc/server": "^11.0.0-rc.825",
@@ -16,9 +19,6 @@
16
19
  },
17
20
  "devDependencies": {
18
21
  "@evjs/cli": "*",
19
- "@evjs/client": "*",
20
- "@evjs/ev": "*",
21
- "@evjs/server": "*",
22
22
  "@types/react": "^19.1.8",
23
23
  "@types/react-dom": "^19.1.8",
24
24
  "typescript": "^6.0.2"
@@ -1,6 +1,6 @@
1
- import { createRootRoute, Outlet } from "@evjs/client";
1
+ import type { ReactNode } from "react";
2
2
 
3
- function Root() {
3
+ export default function Root({ children }: { children?: ReactNode }) {
4
4
  return (
5
5
  <div
6
6
  style={{
@@ -22,11 +22,7 @@ function Root() {
22
22
  Combining Zero-Config Server Functions with tRPC Type-Safety
23
23
  </p>
24
24
  </header>
25
- <main>
26
- <Outlet />
27
- </main>
25
+ <main>{children}</main>
28
26
  </div>
29
27
  );
30
28
  }
31
-
32
- export const rootRoute = createRootRoute({ component: Root });
@@ -1,10 +1,9 @@
1
- import { createRoute, useQuery } from "@evjs/client";
1
+ import { useQuery } from "@evjs/client";
2
2
  import { createTRPCClient, type TRPCLink } from "@trpc/client";
3
3
  import { observable } from "@trpc/server/observable";
4
4
  import { useCallback, useEffect, useState } from "react";
5
5
  import { getServerTime, trpcHandler } from "../api/trpc.server";
6
6
  import type { AppRouter } from "../trpc";
7
- import { rootRoute } from "./__root";
8
7
 
9
8
  // ── tRPC Glue ──
10
9
 
@@ -32,7 +31,7 @@ const trpc = createTRPCClient<AppRouter>({
32
31
 
33
32
  // ── Home Page ──
34
33
 
35
- function HomePage() {
34
+ export default function HomePage() {
36
35
  const [trpcData, setTrpcData] = useState<unknown>(null);
37
36
  const { data: serverTime, refetch: refetchTime } = useQuery(getServerTime);
38
37
 
@@ -102,9 +101,3 @@ function HomePage() {
102
101
  </div>
103
102
  );
104
103
  }
105
-
106
- export const homeRoute = createRoute({
107
- getParentRoute: () => rootRoute,
108
- path: "/",
109
- component: HomePage,
110
- });
@@ -1,15 +0,0 @@
1
- import { createApp } from "@evjs/client";
2
- import { rootRoute } from "./pages/__root";
3
- import { postsRoute } from "./pages/home";
4
-
5
- const routeTree = rootRoute.addChildren([postsRoute]);
6
-
7
- const app = createApp({ routeTree });
8
-
9
- declare module "@evjs/client" {
10
- interface Register {
11
- router: typeof app.router;
12
- }
13
- }
14
-
15
- app.render("#app");
@@ -1,37 +0,0 @@
1
- import {
2
- createApp,
3
- createHashHistory,
4
- createMemoryHistory,
5
- } from "@evjs/client";
6
- import { rootRoute } from "./pages/__root";
7
- import {
8
- aboutRoute,
9
- searchRoute,
10
- userDetailRoute,
11
- usersRoute,
12
- } from "./pages/home";
13
-
14
- const routeTree = rootRoute.addChildren([
15
- usersRoute,
16
- aboutRoute,
17
- userDetailRoute,
18
- searchRoute,
19
- ]);
20
-
21
- const historyType = localStorage.getItem("router_history") || "browser";
22
- const history =
23
- historyType === "hash"
24
- ? createHashHistory()
25
- : historyType === "memory"
26
- ? createMemoryHistory()
27
- : undefined;
28
-
29
- const app = createApp({ routeTree, history });
30
-
31
- declare module "@evjs/client" {
32
- interface Register {
33
- router: typeof app.router;
34
- }
35
- }
36
-
37
- app.render("#app");
@@ -1,49 +0,0 @@
1
- import { createRootRoute, Link, Outlet } from "@evjs/client";
2
-
3
- const navLinkStyle = { textDecoration: "none", color: "#0f172a" };
4
-
5
- function Root() {
6
- const currentHistory = localStorage.getItem("router_history") || "browser";
7
-
8
- const setHistory = (type: string) => {
9
- localStorage.setItem("router_history", type);
10
- window.location.reload();
11
- };
12
-
13
- return (
14
- <div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
15
- <h1>Server Functions Example</h1>
16
- <div style={{ marginBottom: "1rem" }}>
17
- <label htmlFor="history-select" style={{ marginRight: "1rem" }}>
18
- History Type:
19
- </label>
20
- <select
21
- id="history-select"
22
- value={currentHistory}
23
- onChange={(e) => setHistory(e.target.value)}
24
- >
25
- <option value="browser">Browser</option>
26
- <option value="hash">Hash</option>
27
- <option value="memory">Memory</option>
28
- </select>
29
- </div>
30
- <nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
31
- <Link to="/" style={navLinkStyle}>
32
- Users
33
- </Link>
34
- <Link to="/about" style={navLinkStyle}>
35
- Static Route
36
- </Link>
37
- <Link to="/users/$userId" params={{ userId: "1" }} style={navLinkStyle}>
38
- Dynamic Route
39
- </Link>
40
- <Link to="/search" search={{ tab: "all" }} style={navLinkStyle}>
41
- Search Route
42
- </Link>
43
- </nav>
44
- <Outlet />
45
- </div>
46
- );
47
- }
48
-
49
- export const rootRoute = createRootRoute({ component: Root });