@evjs/create-app 0.1.11 → 0.2.0

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
package/README.md CHANGED
@@ -25,7 +25,7 @@ npx @evjs/create-app [name] [options]
25
25
  | **`basic`** | Basic full-stack example with routing and server functions. |
26
26
  | **`mpa`** | Multi-page application with separate page entries. |
27
27
  | **`api-routes`** | Programmatic REST API routes via `createRoute()`. |
28
- | **`complex-routing`** | Nested layouts, loaders, and search params. |
28
+ | **`complex-routing`** | Root layout, loaders, search params, and nested paths. |
29
29
  | **`custom-ws-transport`** | Custom transport example using WebSockets. |
30
30
  | **`plugin-authoring`** | Starter focused on plugin authoring and bundler hooks. |
31
31
  | **`with-sqlite`** | Full-stack CRUD example backed by SQLite. |
@@ -40,6 +40,10 @@ npx @evjs/create-app my-new-app
40
40
 
41
41
  Follow the interactive prompts to select your features and get started in seconds.
42
42
 
43
+ Generated framework artifacts such as `.evjs/` and
44
+ `src/evjs-route-types.d.ts` are not copied from templates; `ev dev` and
45
+ `ev build` recreate them for the new project.
46
+
43
47
  ## License
44
48
 
45
49
  MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export declare function shouldCopyTemplatePath(src: string): boolean;
3
+ export declare function runCreateAppCli(argv?: string[]): Promise<void>;
package/dist/index.js CHANGED
@@ -7,105 +7,129 @@ import pc from "picocolors";
7
7
  import prompts from "prompts";
8
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
9
  const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8"));
10
- const program = new Command();
11
- program
12
- .name("create-evjs-app")
13
- .description("Scaffold a new evjs project")
14
- .version(pkg.version)
15
- .argument("[name]", "Project name")
16
- .option("-t, --template <template>", "Template to use")
17
- .action(async (name, options) => {
18
- const response = await prompts([
19
- {
20
- type: name ? null : "text",
21
- name: "projectName",
22
- message: "Project name:",
23
- initial: name || "my-evjs-app",
24
- },
25
- {
26
- type: options.template ? null : "select",
27
- name: "template",
28
- message: "Select a template:",
29
- choices: [
30
- { title: "Basic (Routing + Server Functions)", value: "basic" },
31
- { title: "MPA (Multi-Page Application)", value: "mpa" },
32
- {
33
- title: "API Routes (Programmatic REST API via createRoute())",
34
- value: "api-routes",
35
- },
36
- {
37
- title: "Complex Routing (params, search, layouts, loaders)",
38
- value: "complex-routing",
39
- },
40
- {
41
- title: "With Tailwind CSS (plugin loaders example)",
42
- value: "with-tailwind",
43
- },
44
- { title: "With tRPC Interop", value: "with-trpc" },
45
- { title: "With SQLite (Full-stack CRUD)", value: "with-sqlite" },
46
- {
47
- title: "Custom Transport (WebSockets)",
48
- value: "custom-ws-transport",
49
- },
50
- { title: "Plugin Authoring", value: "plugin-authoring" },
51
- ],
52
- },
53
- ], {
54
- onCancel: () => {
10
+ const templateCopyExcludedBasenames = new Set([
11
+ "node_modules",
12
+ "dist",
13
+ ".turbo",
14
+ ".turbopack",
15
+ ".evjs",
16
+ "evjs-route-types.d.ts",
17
+ ]);
18
+ export function shouldCopyTemplatePath(src) {
19
+ return !src
20
+ .split(/[\\/]+/)
21
+ .some((segment) => templateCopyExcludedBasenames.has(segment));
22
+ }
23
+ export async function runCreateAppCli(argv = process.argv) {
24
+ const program = new Command();
25
+ program
26
+ .name("create-evjs-app")
27
+ .description("Scaffold a new evjs project")
28
+ .version(pkg.version)
29
+ .argument("[name]", "Project name")
30
+ .option("-t, --template <template>", "Template to use")
31
+ .action(async (name, options) => {
32
+ const response = await prompts([
33
+ {
34
+ type: name ? null : "text",
35
+ name: "projectName",
36
+ message: "Project name:",
37
+ initial: name || "my-evjs-app",
38
+ },
39
+ {
40
+ type: options.template ? null : "select",
41
+ name: "template",
42
+ message: "Select a template:",
43
+ choices: [
44
+ { title: "Basic (Routing + Server Functions)", value: "basic" },
45
+ { title: "MPA (Multi-Page Application)", value: "mpa" },
46
+ {
47
+ title: "API Routes (Programmatic REST API via createRoute())",
48
+ value: "api-routes",
49
+ },
50
+ {
51
+ title: "Complex Routing (params, search, root layout, loaders)",
52
+ value: "complex-routing",
53
+ },
54
+ {
55
+ title: "With Tailwind CSS (plugin loaders example)",
56
+ value: "with-tailwind",
57
+ },
58
+ { title: "With tRPC Interop", value: "with-trpc" },
59
+ { title: "With SQLite (Full-stack CRUD)", value: "with-sqlite" },
60
+ {
61
+ title: "Custom Transport (WebSockets)",
62
+ value: "custom-ws-transport",
63
+ },
64
+ { title: "Plugin Authoring", value: "plugin-authoring" },
65
+ ],
66
+ },
67
+ ], {
68
+ onCancel: () => {
69
+ process.exit(1);
70
+ },
71
+ });
72
+ const projectName = response.projectName || name;
73
+ const template = response.template || options.template;
74
+ const targetDir = path.resolve(process.cwd(), projectName);
75
+ if (fs.existsSync(targetDir)) {
76
+ console.error(pc.red(`✖ Directory ${projectName} already exists!`));
55
77
  process.exit(1);
56
- },
78
+ }
79
+ const templatesRoot = path.resolve(__dirname, "../templates");
80
+ const templateDir = path.resolve(templatesRoot, template);
81
+ // Prevent path traversal outside the templates directory
82
+ if (!templateDir.startsWith(templatesRoot + path.sep)) {
83
+ console.error(pc.red(`✖ Invalid template: ${template}`));
84
+ process.exit(1);
85
+ }
86
+ if (!fs.existsSync(templateDir)) {
87
+ console.error(pc.red(`✖ Template ${template} not found!`));
88
+ process.exit(1);
89
+ }
90
+ console.log(pc.cyan(`⚡ Scaffolding project in ${targetDir}...`));
91
+ fs.cpSync(templateDir, targetDir, {
92
+ recursive: true,
93
+ dereference: true,
94
+ filter: shouldCopyTemplatePath,
95
+ });
96
+ // Post-process package.json: sync @evjs/* versions and set project name
97
+ const pkgPath = path.join(targetDir, "package.json");
98
+ if (fs.existsSync(pkgPath)) {
99
+ const projPkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
100
+ projPkg.name = projectName;
101
+ delete projPkg.private; // Templates shouldn't be private by default
102
+ const updateDeps = (deps) => {
103
+ if (!deps)
104
+ return;
105
+ for (const [depName, val] of Object.entries(deps)) {
106
+ if (depName.startsWith("@evjs/") &&
107
+ (val === "*" ||
108
+ (typeof val === "string" && val.includes("workspace")))) {
109
+ deps[depName] = `^${pkg.version}`;
110
+ }
111
+ }
112
+ };
113
+ updateDeps(projPkg.dependencies);
114
+ updateDeps(projPkg.devDependencies);
115
+ fs.writeFileSync(pkgPath, JSON.stringify(projPkg, null, 2));
116
+ }
117
+ console.log(pc.green("✔ Done! Now run:"));
118
+ console.log(` cd ${projectName}`);
119
+ console.log(" npm install");
120
+ console.log(" npm run dev");
57
121
  });
58
- const projectName = response.projectName || name;
59
- const template = response.template || options.template;
60
- const targetDir = path.resolve(process.cwd(), projectName);
61
- if (fs.existsSync(targetDir)) {
62
- console.error(pc.red(`✖ Directory ${projectName} already exists!`));
122
+ await program.parseAsync(argv);
123
+ }
124
+ function isDirectExecution() {
125
+ const invokedPath = process.argv[1];
126
+ if (!invokedPath)
127
+ return false;
128
+ return path.resolve(invokedPath) === fileURLToPath(import.meta.url);
129
+ }
130
+ if (isDirectExecution()) {
131
+ runCreateAppCli().catch((error) => {
132
+ console.error(error);
63
133
  process.exit(1);
64
- }
65
- const templatesRoot = path.resolve(__dirname, "../templates");
66
- const templateDir = path.resolve(templatesRoot, template);
67
- // Prevent path traversal outside the templates directory
68
- if (!templateDir.startsWith(templatesRoot + path.sep)) {
69
- console.error(pc.red(`✖ Invalid template: ${template}`));
70
- process.exit(1);
71
- }
72
- if (!fs.existsSync(templateDir)) {
73
- console.error(pc.red(`✖ Template ${template} not found!`));
74
- process.exit(1);
75
- }
76
- console.log(pc.cyan(`⚡ Scaffolding project in ${targetDir}...`));
77
- fs.cpSync(templateDir, targetDir, {
78
- recursive: true,
79
- dereference: true,
80
- filter: (src) => {
81
- const basename = path.basename(src);
82
- return !["node_modules", "dist", ".turbo"].includes(basename);
83
- },
84
134
  });
85
- // Post-process package.json: sync @evjs/* versions and set project name
86
- const pkgPath = path.join(targetDir, "package.json");
87
- if (fs.existsSync(pkgPath)) {
88
- const projPkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
89
- projPkg.name = projectName;
90
- delete projPkg.private; // Templates shouldn't be private by default
91
- const updateDeps = (deps) => {
92
- if (!deps)
93
- return;
94
- for (const [depName, val] of Object.entries(deps)) {
95
- if (depName.startsWith("@evjs/") &&
96
- (val === "*" ||
97
- (typeof val === "string" && val.includes("workspace")))) {
98
- deps[depName] = `^${pkg.version}`;
99
- }
100
- }
101
- };
102
- updateDeps(projPkg.dependencies);
103
- updateDeps(projPkg.devDependencies);
104
- fs.writeFileSync(pkgPath, JSON.stringify(projPkg, null, 2));
105
- }
106
- console.log(pc.green("✔ Done! Now run:"));
107
- console.log(` cd ${projectName}`);
108
- console.log(" npm install");
109
- console.log(" npm run dev");
110
- });
111
- program.parse();
135
+ }
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@evjs/create-app",
3
- "version": "0.1.11",
3
+ "version": "0.2.0",
4
4
  "description": "Scaffold a new evjs project",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
7
15
  "bin": {
8
16
  "create-evjs-app": "dist/index.js"
9
17
  },
@@ -12,7 +12,7 @@ npm run dev
12
12
 
13
13
  | File | Purpose |
14
14
  |------|---------|
15
- | `src/server.ts` | Mounts route handlers via `createApp({ routeHandlers })` |
15
+ | `src/server.ts` | Mounts routes via `createApp({ routes })` |
16
16
  | `src/api/posts.routes.ts` | CRUD route handlers for `/api/posts` |
17
17
  | `src/api/health.routes.ts` | Health check endpoint |
18
18
 
@@ -23,7 +23,7 @@ npm run dev
23
23
  - Query string parsing (`?limit=N`)
24
24
  - Custom status codes (201, 204, 404)
25
25
  - Auto `OPTIONS` and `405 Method Not Allowed`
26
- - Mounting handlers via `createApp({ routeHandlers: [...] })`
26
+ - Mounting route handlers via `createApp({ routes: [...] })`
27
27
 
28
28
  ## Try It
29
29
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-api-routes",
3
- "version": "0.1.11",
3
+ "version": "0.2.0",
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,15 +1,13 @@
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 style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
6
6
  <h1>Route Handlers Example</h1>
7
7
  <p style={{ color: "#666" }}>
8
8
  REST endpoints powered by <code>createRoute()</code>
9
9
  </p>
10
- <Outlet />
10
+ {children}
11
11
  </div>
12
12
  );
13
13
  }
14
-
15
- export const rootRoute = createRootRoute({ component: Root });
@@ -1,6 +1,4 @@
1
- import { createRoute } from "@evjs/client";
2
1
  import { useState } from "react";
3
- import { rootRoute } from "./__root";
4
2
 
5
3
  // ── Types ──
6
4
 
@@ -13,7 +11,7 @@ interface Post {
13
11
 
14
12
  // ── Posts Page ──
15
13
 
16
- function PostsPage() {
14
+ export default function PostsPage() {
17
15
  const [posts, setPosts] = useState<Post[]>([]);
18
16
  const [isLoading, setIsLoading] = useState(true);
19
17
  const [error, setError] = useState<string | null>(null);
@@ -234,9 +232,3 @@ function HealthCheck() {
234
232
  </div>
235
233
  );
236
234
  }
237
-
238
- export const postsRoute = createRoute({
239
- getParentRoute: () => rootRoute,
240
- path: "/",
241
- component: PostsPage,
242
- });
@@ -12,15 +12,13 @@ npm run dev
12
12
 
13
13
  | File | Purpose |
14
14
  |------|---------|
15
- | `ev.config.ts` | The central configuration file for evjs |
16
- | `src/main.tsx` | App bootstrap |
17
- | `src/pages/` | Client routes using TanStack Router |
15
+ | `src/layout/index.tsx` | SPA root layout |
16
+ | `src/pages/` | Page route files |
18
17
  | `src/api/users.server.ts` | `"use server"` CRUD functions |
19
18
 
20
19
  ## What It Demonstrates
21
20
 
22
- - `ev.config.ts` setup
23
- - Client-side routing with `createApp` and `createRoute`
21
+ - SPA page routing from `src/pages`
24
22
  - `"use server"` directive for auto-discovered server functions
25
23
  - `useQuery(getUsers)` for type-safe data fetching
26
24
  - `useMutation({ mutationFn: createUser })` for server-side mutations
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-basic",
3
- "version": "0.1.11",
3
+ "version": "0.2.0",
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"
@@ -0,0 +1,27 @@
1
+ import { Link } from "@evjs/client";
2
+ import type { ReactNode } from "react";
3
+
4
+ const navLinkStyle = { textDecoration: "none", color: "#0f172a" };
5
+
6
+ export default function Root({ children }: { children?: ReactNode }) {
7
+ return (
8
+ <div style={{ fontFamily: "system-ui, sans-serif", padding: "1rem" }}>
9
+ <h1>Server Functions Example</h1>
10
+ <nav style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
11
+ <Link to="/" style={navLinkStyle}>
12
+ Users
13
+ </Link>
14
+ <Link to="/about" style={navLinkStyle}>
15
+ Static Route
16
+ </Link>
17
+ <Link to="/users/$userId" params={{ userId: "1" }} style={navLinkStyle}>
18
+ Dynamic Route
19
+ </Link>
20
+ <Link to="/search" search={{ tab: "all" }} style={navLinkStyle}>
21
+ Search Route
22
+ </Link>
23
+ </nav>
24
+ {children}
25
+ </div>
26
+ );
27
+ }
@@ -0,0 +1,17 @@
1
+ const cardStyle = {
2
+ border: "1px solid #e2e8f0",
3
+ borderRadius: 12,
4
+ padding: "1rem",
5
+ };
6
+
7
+ export default function AboutPage() {
8
+ return (
9
+ <div style={cardStyle}>
10
+ <h2>Static Route</h2>
11
+ <p>
12
+ This page is discovered from <code>src/pages/about.tsx</code> and served
13
+ at <code>/about</code>.
14
+ </p>
15
+ </div>
16
+ );
17
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ getFnQueryKey,
3
+ Link,
4
+ useMutation,
5
+ useQuery,
6
+ useQueryClient,
7
+ } from "@evjs/client";
8
+ import { useState } from "react";
9
+ import { createUser, getUsers } from "../api/users.server";
10
+
11
+ const cardStyle = {
12
+ border: "1px solid #e2e8f0",
13
+ borderRadius: 12,
14
+ padding: "1rem",
15
+ };
16
+
17
+ const linkStyle = { color: "#2563eb", textDecoration: "none" };
18
+
19
+ export default function UsersPage() {
20
+ const [name, setName] = useState("");
21
+ const [email, setEmail] = useState("");
22
+ const queryClient = useQueryClient();
23
+
24
+ const { data: users = [], isLoading } = useQuery(getUsers);
25
+ const createUserMutation = useMutation({
26
+ mutationFn: createUser,
27
+ onSuccess: () => {
28
+ queryClient.invalidateQueries({ queryKey: getFnQueryKey(getUsers) });
29
+ setName("");
30
+ setEmail("");
31
+ },
32
+ });
33
+
34
+ function handleCreate(e: { preventDefault: () => void }) {
35
+ e.preventDefault();
36
+ if (!name || !email) return;
37
+ createUserMutation.mutate({ name, email });
38
+ }
39
+
40
+ if (isLoading) return <p>Loading users from server...</p>;
41
+
42
+ return (
43
+ <div style={{ display: "grid", gap: "1rem" }}>
44
+ <div style={cardStyle}>
45
+ <h2>Routing Patterns</h2>
46
+ <p style={{ color: "#475569" }}>
47
+ Page files cover static, dynamic-param, and search-param pages with
48
+ framework-managed routing glue.
49
+ </p>
50
+ <div style={{ display: "flex", gap: "1rem", flexWrap: "wrap" }}>
51
+ <Link to="/about" style={linkStyle}>
52
+ Open static route
53
+ </Link>
54
+ <Link to="/users/$userId" params={{ userId: "2" }} style={linkStyle}>
55
+ Open dynamic route
56
+ </Link>
57
+ <Link to="/search" search={{ tab: "favorites" }} style={linkStyle}>
58
+ Open search route
59
+ </Link>
60
+ </div>
61
+ </div>
62
+
63
+ <div style={cardStyle}>
64
+ <h2>Users</h2>
65
+ <ul>
66
+ {users.map((u) => (
67
+ <li key={u.id}>
68
+ <Link
69
+ to="/users/$userId"
70
+ params={{ userId: u.id }}
71
+ style={linkStyle}
72
+ >
73
+ {u.name}
74
+ </Link>{" "}
75
+ - {u.email}
76
+ </li>
77
+ ))}
78
+ </ul>
79
+
80
+ <h3>Add User</h3>
81
+ <form
82
+ onSubmit={handleCreate}
83
+ style={{ display: "flex", gap: "0.5rem" }}
84
+ >
85
+ <input
86
+ placeholder="Name"
87
+ value={name}
88
+ onChange={(e) => setName(e.target.value)}
89
+ />
90
+ <input
91
+ placeholder="Email"
92
+ value={email}
93
+ onChange={(e) => setEmail(e.target.value)}
94
+ />
95
+ <button type="submit">Create</button>
96
+ </form>
97
+ </div>
98
+ </div>
99
+ );
100
+ }
@@ -0,0 +1,58 @@
1
+ import { Link, usePageSearch, useQuery } from "@evjs/client";
2
+ import { getUsers } from "../api/users.server";
3
+
4
+ const cardStyle = {
5
+ border: "1px solid #e2e8f0",
6
+ borderRadius: 12,
7
+ padding: "1rem",
8
+ };
9
+
10
+ const linkStyle = { color: "#2563eb", textDecoration: "none" };
11
+
12
+ export function validateSearch(search: Record<string, unknown>) {
13
+ return {
14
+ tab:
15
+ search.tab === "favorites" || search.tab === "recent"
16
+ ? search.tab
17
+ : "all",
18
+ };
19
+ }
20
+
21
+ export default function SearchPage() {
22
+ const search = usePageSearch();
23
+ const tab =
24
+ search.tab === "favorites" || search.tab === "recent" ? search.tab : "all";
25
+ const { data: users = [] } = useQuery(getUsers);
26
+
27
+ const visibleUsers =
28
+ tab === "favorites"
29
+ ? users.filter((user) => Number.parseInt(user.id, 10) % 2 === 1)
30
+ : tab === "recent"
31
+ ? users.slice(-2)
32
+ : users;
33
+
34
+ return (
35
+ <div style={cardStyle}>
36
+ <h2>Search Route</h2>
37
+ <p style={{ color: "#64748b" }}>Current search tab: {tab}</p>
38
+ <div style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}>
39
+ <Link to="/search" search={{ tab: "all" }} style={linkStyle}>
40
+ All
41
+ </Link>
42
+ <Link to="/search" search={{ tab: "favorites" }} style={linkStyle}>
43
+ Favorites
44
+ </Link>
45
+ <Link to="/search" search={{ tab: "recent" }} style={linkStyle}>
46
+ Recent
47
+ </Link>
48
+ </div>
49
+ <ul>
50
+ {visibleUsers.map((user) => (
51
+ <li key={user.id}>
52
+ {user.name} - {user.email}
53
+ </li>
54
+ ))}
55
+ </ul>
56
+ </div>
57
+ );
58
+ }
@@ -0,0 +1,31 @@
1
+ import { Link, usePageParams, useQuery } from "@evjs/client";
2
+ import { getUser } from "../../api/users.server";
3
+
4
+ const cardStyle = {
5
+ border: "1px solid #e2e8f0",
6
+ borderRadius: 12,
7
+ padding: "1rem",
8
+ };
9
+
10
+ const linkStyle = { color: "#2563eb", textDecoration: "none" };
11
+
12
+ export default function UserDetailPage() {
13
+ const { userId } = usePageParams();
14
+ const { data: user, isLoading } = useQuery(getUser, userId);
15
+
16
+ if (isLoading) return <p>Loading user...</p>;
17
+
18
+ return (
19
+ <div style={cardStyle}>
20
+ <h2>Dynamic Route</h2>
21
+ <p style={{ color: "#64748b" }}>Path param: {userId}</p>
22
+ <p>
23
+ Selected user: <strong>{user?.name}</strong>
24
+ </p>
25
+ <p>{user?.email}</p>
26
+ <Link to="/" style={linkStyle}>
27
+ Back to users
28
+ </Link>
29
+ </div>
30
+ );
31
+ }