@evjs/create-app 0.0.26 → 0.0.28
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.
- package/README.md +1 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
- package/templates/basic-csr/package.json +1 -1
- package/templates/basic-fns-ecma/package.json +1 -1
- package/templates/basic-mpa/README.md +31 -0
- package/templates/basic-mpa/ev.config.ts +14 -0
- package/templates/basic-mpa/index.html +11 -0
- package/templates/basic-mpa/package.json +21 -0
- package/templates/basic-mpa/src/about/main.tsx +23 -0
- package/templates/basic-mpa/src/home/main.tsx +23 -0
- package/templates/basic-mpa/tsconfig.json +18 -0
- package/templates/basic-plugins/README.md +2 -2
- package/templates/basic-plugins/ev.config.ts +3 -11
- package/templates/basic-plugins/package.json +1 -3
- package/templates/basic-server-fns/package.json +1 -1
- package/templates/basic-server-routes/package.json +1 -1
- package/templates/complex-routing/README.md +17 -13
- package/templates/complex-routing/ev.config.ts +14 -0
- package/templates/complex-routing/index.html +9 -9
- package/templates/complex-routing/package.json +2 -4
- package/templates/complex-routing/src/about/main.tsx +23 -0
- package/templates/complex-routing/src/home/main.tsx +23 -0
- package/templates/complex-routing/tsconfig.json +11 -6
- package/templates/configured-server-fns/package.json +1 -1
- package/templates/server-fns-query/package.json +1 -1
- package/templates/server-fns-query/src/api/posts.server.ts +1 -1
- package/templates/sqlite-server-fns/package.json +1 -1
- package/templates/trpc-server-fns/package.json +1 -1
- package/templates/websocket-fns/package.json +1 -1
- package/templates/with-tailwind/package.json +1 -1
- package/templates/complex-routing/src/api/data.server.ts +0 -86
- package/templates/complex-routing/src/main.tsx +0 -29
- package/templates/complex-routing/src/pages/__root.tsx +0 -60
- package/templates/complex-routing/src/pages/catch.tsx +0 -26
- package/templates/complex-routing/src/pages/dashboard.tsx +0 -79
- package/templates/complex-routing/src/pages/home.tsx +0 -35
- package/templates/complex-routing/src/pages/posts/index.tsx +0 -100
- package/templates/complex-routing/src/pages/search.tsx +0 -71
- package/templates/complex-routing/src/pages/user.tsx +0 -28
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ npx @evjs/create-app [name] [options]
|
|
|
23
23
|
| Name | Description |
|
|
24
24
|
|------|-------------|
|
|
25
25
|
| **`basic-csr`** | Client-side only (React + TanStack Router). |
|
|
26
|
+
| **`basic-mpa`** | Multi-page application with shared HTML template. |
|
|
26
27
|
| **`basic-server-fns`** | Basic full-stack with server functions. |
|
|
27
28
|
| **`configured-server-fns`** | Full-stack with `@evjs/create-app` + `ev.config.ts`. |
|
|
28
29
|
| **`complex-routing`** | Nested layouts, loaders, and search params. |
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,10 @@ program
|
|
|
28
28
|
message: "Select a template:",
|
|
29
29
|
choices: [
|
|
30
30
|
{ title: "Basic CSR (Client-Side Rendering)", value: "basic-csr" },
|
|
31
|
+
{
|
|
32
|
+
title: "Basic MPA (Multi-Page Application)",
|
|
33
|
+
value: "basic-mpa",
|
|
34
|
+
},
|
|
31
35
|
{ title: "Basic Server Functions", value: "basic-server-fns" },
|
|
32
36
|
{
|
|
33
37
|
title: "Basic Server Routes (Programmatic REST API via createRoute())",
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# basic-mpa
|
|
2
|
+
|
|
3
|
+
Minimal multi-page application example using evjs `pages` config.
|
|
4
|
+
|
|
5
|
+
## Run
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev -w example-basic-mpa
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Build
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm run build -w example-basic-mpa
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Key Files
|
|
18
|
+
|
|
19
|
+
| File | Purpose |
|
|
20
|
+
|------|---------|
|
|
21
|
+
| `ev.config.ts` | Enables MPA mode and defines page entries |
|
|
22
|
+
| `index.html` | Shared HTML template for all pages |
|
|
23
|
+
| `src/home/main.tsx` | Home page React entry |
|
|
24
|
+
| `src/about/main.tsx` | About page React entry |
|
|
25
|
+
|
|
26
|
+
## What It Demonstrates
|
|
27
|
+
|
|
28
|
+
- Multi-page build via `pages`
|
|
29
|
+
- Independent React entry for each page
|
|
30
|
+
- Shared HTML template reused by all pages
|
|
31
|
+
- Static links between pages
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example-basic-mpa",
|
|
3
|
+
"version": "0.0.28",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "npx ev dev",
|
|
7
|
+
"build": "npx ev build",
|
|
8
|
+
"check-types": "tsc --noEmit"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"react": "^19.2.4",
|
|
12
|
+
"react-dom": "^19.2.4"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@evjs/cli": "*",
|
|
16
|
+
"@evjs/ev": "*",
|
|
17
|
+
"@types/react": "^19.1.8",
|
|
18
|
+
"@types/react-dom": "^19.1.8",
|
|
19
|
+
"typescript": "^6.0.2"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRoot } from "react-dom/client";
|
|
2
|
+
|
|
3
|
+
function AboutPage() {
|
|
4
|
+
return (
|
|
5
|
+
<main style={{ fontFamily: "ui-sans-serif, system-ui", margin: "2rem" }}>
|
|
6
|
+
<h1>About Page</h1>
|
|
7
|
+
<p>
|
|
8
|
+
This page is rendered from <code>src/about/main.tsx</code>.
|
|
9
|
+
</p>
|
|
10
|
+
<p>
|
|
11
|
+
<a href="/home.html">Back to Home page</a>
|
|
12
|
+
</p>
|
|
13
|
+
</main>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rootEl = document.getElementById("app");
|
|
18
|
+
|
|
19
|
+
if (!rootEl) {
|
|
20
|
+
throw new Error("Missing #app mount element");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
createRoot(rootEl).render(<AboutPage />);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRoot } from "react-dom/client";
|
|
2
|
+
|
|
3
|
+
function HomePage() {
|
|
4
|
+
return (
|
|
5
|
+
<main style={{ fontFamily: "ui-sans-serif, system-ui", margin: "2rem" }}>
|
|
6
|
+
<h1>Home Page</h1>
|
|
7
|
+
<p>
|
|
8
|
+
This page is rendered from <code>src/home/main.tsx</code>.
|
|
9
|
+
</p>
|
|
10
|
+
<p>
|
|
11
|
+
<a href="/about.html">Go to About page</a>
|
|
12
|
+
</p>
|
|
13
|
+
</main>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rootEl = document.getElementById("app");
|
|
18
|
+
|
|
19
|
+
if (!rootEl) {
|
|
20
|
+
throw new Error("Missing #app mount element");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
createRoot(rootEl).render(<HomePage />);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src"]
|
|
18
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Demonstrates the evjs plugin system with all available hooks:
|
|
4
4
|
|
|
5
|
-
- **`bundler`** — modify the underlying bundler config (type-safe via `
|
|
5
|
+
- **`bundler`** — modify the underlying bundler config (type-safe via `utoopack()` helper)
|
|
6
6
|
- **`buildStart`** — run logic before compilation begins
|
|
7
7
|
- **`buildEnd`** — run logic after compilation completes
|
|
8
8
|
- **`transformHtml`** — modify the parsed HTML document after asset injection
|
|
@@ -17,4 +17,4 @@ npm run dev
|
|
|
17
17
|
|
|
18
18
|
1. Console output from `buildStart` and `buildEnd` hooks during build
|
|
19
19
|
2. The `<!-- Built with evjs | N asset(s) -->` comment in the output HTML (injected by `transformHtml`)
|
|
20
|
-
3. `.txt` file support added via the `bundler` hook (
|
|
20
|
+
3. `.txt` file support added via the `bundler` hook (utoopack raw rule)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { utoopack } from "@evjs/bundler-utoopack";
|
|
2
|
-
import { webpack } from "@evjs/bundler-webpack";
|
|
3
2
|
import { defineConfig } from "@evjs/ev";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Example: evjs plugin system.
|
|
7
6
|
*
|
|
8
7
|
* Demonstrates all available plugin hooks:
|
|
9
|
-
* - `bundlerConfig` — modify the underlying bundler config (type-safe via
|
|
8
|
+
* - `bundlerConfig` — modify the underlying bundler config (type-safe via utoopack() helper)
|
|
10
9
|
* - `buildStart` — run logic before compilation begins
|
|
11
10
|
* - `buildEnd` — run logic after compilation completes
|
|
12
11
|
* - `transformHtml` — modify the output HTML document after asset injection
|
|
@@ -25,16 +24,9 @@ export default defineConfig({
|
|
|
25
24
|
console.log("[example-txt-plugin] build starting...");
|
|
26
25
|
},
|
|
27
26
|
|
|
28
|
-
// Type-safe bundler config mutation via
|
|
29
|
-
//
|
|
27
|
+
// Type-safe bundler config mutation via the utoopack helper.
|
|
28
|
+
// This hook only runs when utoopack is the active bundler.
|
|
30
29
|
bundlerConfig(config, ctx) {
|
|
31
|
-
webpack((cfg) => {
|
|
32
|
-
cfg.module?.rules?.push({
|
|
33
|
-
test: /\.txt$/,
|
|
34
|
-
use: "raw-loader",
|
|
35
|
-
});
|
|
36
|
-
})(config, ctx);
|
|
37
|
-
|
|
38
30
|
utoopack((cfg) => {
|
|
39
31
|
// Add custom loaders or rules to utoopack
|
|
40
32
|
cfg.module ??= {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-basic-plugins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npx ev dev",
|
|
@@ -12,14 +12,12 @@
|
|
|
12
12
|
"react-dom": "^19.2.4"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@evjs/bundler-webpack": "*",
|
|
16
15
|
"@evjs/cli": "*",
|
|
17
16
|
"@evjs/client": "*",
|
|
18
17
|
"@evjs/ev": "*",
|
|
19
18
|
"@evjs/server": "*",
|
|
20
19
|
"@types/react": "^19.1.8",
|
|
21
20
|
"@types/react-dom": "^19.1.8",
|
|
22
|
-
"raw-loader": "^4.0.2",
|
|
23
21
|
"typescript": "^6.0.2"
|
|
24
22
|
}
|
|
25
23
|
}
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# basic-mpa
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Minimal multi-page application example using evjs `pages` config.
|
|
4
4
|
|
|
5
5
|
## Run
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm run dev -w example-
|
|
8
|
+
npm run dev -w example-basic-mpa
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Build
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm run build -w example-basic-mpa
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
## Key Files
|
|
12
18
|
|
|
13
19
|
| File | Purpose |
|
|
14
20
|
|------|---------|
|
|
15
|
-
| `
|
|
16
|
-
| `
|
|
17
|
-
| `src/
|
|
18
|
-
| `src/
|
|
21
|
+
| `ev.config.ts` | Enables MPA mode and defines page entries |
|
|
22
|
+
| `index.html` | Shared HTML template for all pages |
|
|
23
|
+
| `src/home/main.tsx` | Home page React entry |
|
|
24
|
+
| `src/about/main.tsx` | About page React entry |
|
|
19
25
|
|
|
20
26
|
## What It Demonstrates
|
|
21
27
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
- Catch-all 404 route
|
|
27
|
-
- Type-safe `route.useParams()`
|
|
28
|
+
- Multi-page build via `pages`
|
|
29
|
+
- Independent React entry for each page
|
|
30
|
+
- Shared HTML template reused by all pages
|
|
31
|
+
- Static links between pages
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
|
|
10
|
-
</body>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>ev - Basic MPA Example</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
</body>
|
|
11
11
|
</html>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "example-
|
|
3
|
-
"version": "0.0.
|
|
2
|
+
"name": "example-basic-mpa",
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npx ev dev",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@evjs/cli": "*",
|
|
16
|
-
"@evjs/client": "*",
|
|
17
16
|
"@evjs/ev": "*",
|
|
18
|
-
"@evjs/server": "*",
|
|
19
17
|
"@types/react": "^19.1.8",
|
|
20
18
|
"@types/react-dom": "^19.1.8",
|
|
21
19
|
"typescript": "^6.0.2"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRoot } from "react-dom/client";
|
|
2
|
+
|
|
3
|
+
function AboutPage() {
|
|
4
|
+
return (
|
|
5
|
+
<main style={{ fontFamily: "ui-sans-serif, system-ui", margin: "2rem" }}>
|
|
6
|
+
<h1>About Page</h1>
|
|
7
|
+
<p>
|
|
8
|
+
This page is rendered from <code>src/about/main.tsx</code>.
|
|
9
|
+
</p>
|
|
10
|
+
<p>
|
|
11
|
+
<a href="/home.html">Back to Home page</a>
|
|
12
|
+
</p>
|
|
13
|
+
</main>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rootEl = document.getElementById("app");
|
|
18
|
+
|
|
19
|
+
if (!rootEl) {
|
|
20
|
+
throw new Error("Missing #app mount element");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
createRoot(rootEl).render(<AboutPage />);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRoot } from "react-dom/client";
|
|
2
|
+
|
|
3
|
+
function HomePage() {
|
|
4
|
+
return (
|
|
5
|
+
<main style={{ fontFamily: "ui-sans-serif, system-ui", margin: "2rem" }}>
|
|
6
|
+
<h1>Home Page</h1>
|
|
7
|
+
<p>
|
|
8
|
+
This page is rendered from <code>src/home/main.tsx</code>.
|
|
9
|
+
</p>
|
|
10
|
+
<p>
|
|
11
|
+
<a href="/about.html">Go to About page</a>
|
|
12
|
+
</p>
|
|
13
|
+
</main>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rootEl = document.getElementById("app");
|
|
18
|
+
|
|
19
|
+
if (!rootEl) {
|
|
20
|
+
throw new Error("Missing #app mount element");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
createRoot(rootEl).render(<HomePage />);
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
3
|
+
"target": "ESNext",
|
|
6
4
|
"jsx": "react-jsx",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"noEmit": true,
|
|
9
11
|
"skipLibCheck": true,
|
|
10
|
-
"
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true
|
|
11
16
|
},
|
|
12
17
|
"include": ["src"]
|
|
13
18
|
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
|
|
3
|
-
// ── Mock data ──
|
|
4
|
-
|
|
5
|
-
const posts = [
|
|
6
|
-
{
|
|
7
|
-
id: "1",
|
|
8
|
-
title: "Getting Started with evjs",
|
|
9
|
-
body: "evjs is a zero-config React fullstack framework...",
|
|
10
|
-
author: "alice",
|
|
11
|
-
tags: ["intro", "tutorial"],
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
id: "2",
|
|
15
|
-
title: "Server Functions Deep Dive",
|
|
16
|
-
body: 'Server functions use the "use server" directive...',
|
|
17
|
-
author: "bob",
|
|
18
|
-
tags: ["server", "advanced"],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
id: "3",
|
|
22
|
-
title: "Routing Patterns",
|
|
23
|
-
body: "evjs uses TanStack Router for type-safe routing...",
|
|
24
|
-
author: "alice",
|
|
25
|
-
tags: ["routing", "tutorial"],
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
id: "4",
|
|
29
|
-
title: "WebSocket Transport",
|
|
30
|
-
body: "You can swap HTTP for WebSocket transport...",
|
|
31
|
-
author: "charlie",
|
|
32
|
-
tags: ["transport", "advanced"],
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id: "5",
|
|
36
|
-
title: "Deploying to Edge",
|
|
37
|
-
body: "Run your evjs app on Deno, Bun, or Workers...",
|
|
38
|
-
author: "bob",
|
|
39
|
-
tags: ["deploy", "edge"],
|
|
40
|
-
},
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
const users: Record<string, { name: string; bio: string }> = {
|
|
44
|
-
alice: { name: "Alice", bio: "Core contributor" },
|
|
45
|
-
bob: { name: "Bob", bio: "Technical writer" },
|
|
46
|
-
charlie: { name: "Charlie", bio: "DevOps engineer" },
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// ── Server functions ──
|
|
50
|
-
|
|
51
|
-
export async function getPosts(query?: string) {
|
|
52
|
-
await delay(50);
|
|
53
|
-
if (!query) return posts;
|
|
54
|
-
const q = query.toLowerCase();
|
|
55
|
-
return posts.filter(
|
|
56
|
-
(p) =>
|
|
57
|
-
p.title.toLowerCase().includes(q) || p.tags.some((t) => t.includes(q)),
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function getPost(id: string) {
|
|
62
|
-
await delay(50);
|
|
63
|
-
const post = posts.find((p) => p.id === id);
|
|
64
|
-
if (!post) throw new Error(`Post ${id} not found`);
|
|
65
|
-
return post;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function getUser(username: string) {
|
|
69
|
-
await delay(50);
|
|
70
|
-
const user = users[username];
|
|
71
|
-
if (!user) throw new Error(`User ${username} not found`);
|
|
72
|
-
return { username, ...user };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function getStats() {
|
|
76
|
-
await delay(50);
|
|
77
|
-
return {
|
|
78
|
-
totalPosts: posts.length,
|
|
79
|
-
totalUsers: Object.keys(users).length,
|
|
80
|
-
tags: [...new Set(posts.flatMap((p) => p.tags))],
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function delay(ms: number) {
|
|
85
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
86
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createApp } from "@evjs/client";
|
|
2
|
-
import { rootRoute } from "./pages/__root";
|
|
3
|
-
import { notFoundRoute, redirectRoute } from "./pages/catch";
|
|
4
|
-
import { dashboardLayout, dashboardRoute } from "./pages/dashboard";
|
|
5
|
-
import { homeRoute } from "./pages/home";
|
|
6
|
-
import { postDetailRoute, postsIndexRoute, postsRoute } from "./pages/posts";
|
|
7
|
-
import { searchRoute } from "./pages/search";
|
|
8
|
-
import { userRoute } from "./pages/user";
|
|
9
|
-
|
|
10
|
-
const routeTree = rootRoute.addChildren([
|
|
11
|
-
homeRoute,
|
|
12
|
-
postsRoute.addChildren([postsIndexRoute, postDetailRoute]),
|
|
13
|
-
userRoute,
|
|
14
|
-
dashboardLayout.addChildren([dashboardRoute]),
|
|
15
|
-
searchRoute,
|
|
16
|
-
redirectRoute,
|
|
17
|
-
notFoundRoute,
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
const app = createApp({ routeTree });
|
|
21
|
-
|
|
22
|
-
// Register router type for full IDE type-safety on useParams, useSearch, Link, etc.
|
|
23
|
-
declare module "@tanstack/react-router" {
|
|
24
|
-
interface Register {
|
|
25
|
-
router: typeof app.router;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
app.render("#app");
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { createAppRootRoute, Link, Outlet } from "@evjs/client";
|
|
2
|
-
|
|
3
|
-
const styles = {
|
|
4
|
-
app: {
|
|
5
|
-
fontFamily: "system-ui, sans-serif",
|
|
6
|
-
maxWidth: 900,
|
|
7
|
-
margin: "0 auto",
|
|
8
|
-
padding: "1rem",
|
|
9
|
-
},
|
|
10
|
-
nav: {
|
|
11
|
-
display: "flex",
|
|
12
|
-
gap: "1rem",
|
|
13
|
-
padding: "0.75rem 0",
|
|
14
|
-
borderBottom: "1px solid #e5e7eb",
|
|
15
|
-
marginBottom: "1rem",
|
|
16
|
-
},
|
|
17
|
-
link: { textDecoration: "none", color: "#6b7280" },
|
|
18
|
-
activeLink: { color: "#111", fontWeight: 600 as const },
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function RootLayout() {
|
|
22
|
-
return (
|
|
23
|
-
<div style={styles.app}>
|
|
24
|
-
<nav style={styles.nav}>
|
|
25
|
-
<Link
|
|
26
|
-
to="/"
|
|
27
|
-
style={styles.link}
|
|
28
|
-
activeProps={{ style: styles.activeLink }}
|
|
29
|
-
>
|
|
30
|
-
Home
|
|
31
|
-
</Link>
|
|
32
|
-
<Link
|
|
33
|
-
to="/posts"
|
|
34
|
-
style={styles.link}
|
|
35
|
-
activeProps={{ style: styles.activeLink }}
|
|
36
|
-
>
|
|
37
|
-
Posts
|
|
38
|
-
</Link>
|
|
39
|
-
<Link
|
|
40
|
-
to="/dashboard"
|
|
41
|
-
style={styles.link}
|
|
42
|
-
activeProps={{ style: styles.activeLink }}
|
|
43
|
-
>
|
|
44
|
-
Dashboard
|
|
45
|
-
</Link>
|
|
46
|
-
<Link
|
|
47
|
-
to="/search"
|
|
48
|
-
search={{ q: "" }}
|
|
49
|
-
style={styles.link}
|
|
50
|
-
activeProps={{ style: styles.activeLink }}
|
|
51
|
-
>
|
|
52
|
-
Search
|
|
53
|
-
</Link>
|
|
54
|
-
</nav>
|
|
55
|
-
<Outlet />
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const rootRoute = createAppRootRoute({ component: RootLayout });
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createRoute, Link, redirect } from "@evjs/client";
|
|
2
|
-
import { rootRoute } from "./__root";
|
|
3
|
-
|
|
4
|
-
// ── Redirect: /old-blog → /posts ──
|
|
5
|
-
|
|
6
|
-
export const redirectRoute = createRoute({
|
|
7
|
-
getParentRoute: () => rootRoute,
|
|
8
|
-
path: "/old-blog",
|
|
9
|
-
beforeLoad: () => {
|
|
10
|
-
throw redirect({ to: "/posts" });
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// ── 404 Catch-all ──
|
|
15
|
-
|
|
16
|
-
export const notFoundRoute = createRoute({
|
|
17
|
-
getParentRoute: () => rootRoute,
|
|
18
|
-
path: "*",
|
|
19
|
-
component: () => (
|
|
20
|
-
<div style={{ textAlign: "center", padding: "3rem" }}>
|
|
21
|
-
<h1 style={{ fontSize: 48 }}>404</h1>
|
|
22
|
-
<p style={{ color: "#6b7280" }}>Page not found</p>
|
|
23
|
-
<Link to="/">← Go home</Link>
|
|
24
|
-
</div>
|
|
25
|
-
),
|
|
26
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { createRoute, Outlet, useQuery } from "@evjs/client";
|
|
2
|
-
import { getStats } from "../api/data.server";
|
|
3
|
-
import { rootRoute } from "./__root";
|
|
4
|
-
|
|
5
|
-
const styles = {
|
|
6
|
-
card: {
|
|
7
|
-
border: "1px solid #e5e7eb",
|
|
8
|
-
borderRadius: 8,
|
|
9
|
-
padding: "1rem",
|
|
10
|
-
marginBottom: "0.75rem",
|
|
11
|
-
},
|
|
12
|
-
stat: { textAlign: "center" as const, padding: "1rem" },
|
|
13
|
-
tag: {
|
|
14
|
-
display: "inline-block",
|
|
15
|
-
background: "#f3f4f6",
|
|
16
|
-
borderRadius: 4,
|
|
17
|
-
padding: "2px 8px",
|
|
18
|
-
fontSize: 12,
|
|
19
|
-
marginRight: 4,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// ── Pathless layout (no URL segment, just shared UI) ──
|
|
24
|
-
|
|
25
|
-
export const dashboardLayout = createRoute({
|
|
26
|
-
getParentRoute: () => rootRoute,
|
|
27
|
-
id: "dashboard-layout",
|
|
28
|
-
component: () => (
|
|
29
|
-
<div>
|
|
30
|
-
<Outlet />
|
|
31
|
-
</div>
|
|
32
|
-
),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// ── Dashboard page (/dashboard) ──
|
|
36
|
-
|
|
37
|
-
function Dashboard() {
|
|
38
|
-
const { data: stats } = useQuery(getStats);
|
|
39
|
-
if (!stats) return <p>Loading...</p>;
|
|
40
|
-
return (
|
|
41
|
-
<div>
|
|
42
|
-
<h2>Dashboard</h2>
|
|
43
|
-
<div style={{ display: "flex", gap: "1rem" }}>
|
|
44
|
-
<div style={{ ...styles.card, ...styles.stat }}>
|
|
45
|
-
<div style={{ fontSize: 32, fontWeight: 700 }}>
|
|
46
|
-
{stats.totalPosts}
|
|
47
|
-
</div>
|
|
48
|
-
<div style={{ color: "#6b7280" }}>Posts</div>
|
|
49
|
-
</div>
|
|
50
|
-
<div style={{ ...styles.card, ...styles.stat }}>
|
|
51
|
-
<div style={{ fontSize: 32, fontWeight: 700 }}>
|
|
52
|
-
{stats.totalUsers}
|
|
53
|
-
</div>
|
|
54
|
-
<div style={{ color: "#6b7280" }}>Users</div>
|
|
55
|
-
</div>
|
|
56
|
-
<div style={{ ...styles.card, ...styles.stat }}>
|
|
57
|
-
<div style={{ fontSize: 32, fontWeight: 700 }}>
|
|
58
|
-
{stats.tags.length}
|
|
59
|
-
</div>
|
|
60
|
-
<div style={{ color: "#6b7280" }}>Tags</div>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
<h3>All Tags</h3>
|
|
64
|
-
<div>
|
|
65
|
-
{stats.tags.map((t) => (
|
|
66
|
-
<span key={t} style={styles.tag}>
|
|
67
|
-
{t}
|
|
68
|
-
</span>
|
|
69
|
-
))}
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const dashboardRoute = createRoute({
|
|
76
|
-
getParentRoute: () => dashboardLayout,
|
|
77
|
-
path: "/dashboard",
|
|
78
|
-
component: Dashboard,
|
|
79
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createRoute, Link } from "@evjs/client";
|
|
2
|
-
import { rootRoute } from "./__root";
|
|
3
|
-
|
|
4
|
-
export const homeRoute = createRoute({
|
|
5
|
-
getParentRoute: () => rootRoute,
|
|
6
|
-
path: "/",
|
|
7
|
-
component: () => (
|
|
8
|
-
<div>
|
|
9
|
-
<h1>evjs Complex Routing Example</h1>
|
|
10
|
-
<p>
|
|
11
|
-
Demonstrates nested layouts, dynamic params, search params, redirects,
|
|
12
|
-
and server function loaders.
|
|
13
|
-
</p>
|
|
14
|
-
<ul>
|
|
15
|
-
<li>
|
|
16
|
-
<Link to="/posts">Posts</Link> — nested group with dynamic{" "}
|
|
17
|
-
<code>$postId</code>
|
|
18
|
-
</li>
|
|
19
|
-
<li>
|
|
20
|
-
<Link to="/dashboard">Dashboard</Link> — pathless layout with server
|
|
21
|
-
function loader
|
|
22
|
-
</li>
|
|
23
|
-
<li>
|
|
24
|
-
<Link to="/search" search={{ q: "tutorial" }}>
|
|
25
|
-
Search
|
|
26
|
-
</Link>{" "}
|
|
27
|
-
— search params
|
|
28
|
-
</li>
|
|
29
|
-
<li>
|
|
30
|
-
<Link to="/old-blog">Old Blog</Link> — redirect to /posts
|
|
31
|
-
</li>
|
|
32
|
-
</ul>
|
|
33
|
-
</div>
|
|
34
|
-
),
|
|
35
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { createRoute, Link, Outlet, useQuery } from "@evjs/client";
|
|
2
|
-
import { getPost, getPosts } from "../../api/data.server";
|
|
3
|
-
import { rootRoute } from "../__root";
|
|
4
|
-
|
|
5
|
-
const styles = {
|
|
6
|
-
sidebar: { display: "flex", gap: "1.5rem" },
|
|
7
|
-
nav: {
|
|
8
|
-
minWidth: 180,
|
|
9
|
-
borderRight: "1px solid #e5e7eb",
|
|
10
|
-
paddingRight: "1rem",
|
|
11
|
-
},
|
|
12
|
-
tag: {
|
|
13
|
-
display: "inline-block",
|
|
14
|
-
background: "#f3f4f6",
|
|
15
|
-
borderRadius: 4,
|
|
16
|
-
padding: "2px 8px",
|
|
17
|
-
fontSize: 12,
|
|
18
|
-
marginRight: 4,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// ── Posts layout (/posts) ──
|
|
23
|
-
|
|
24
|
-
function PostsLayout() {
|
|
25
|
-
const { data: posts } = useQuery(getPosts);
|
|
26
|
-
return (
|
|
27
|
-
<div style={styles.sidebar}>
|
|
28
|
-
<div style={styles.nav}>
|
|
29
|
-
<h3 style={{ marginTop: 0 }}>Posts</h3>
|
|
30
|
-
<ul style={{ listStyle: "none", padding: 0 }}>
|
|
31
|
-
{posts?.map((p) => (
|
|
32
|
-
<li key={p.id} style={{ marginBottom: "0.25rem" }}>
|
|
33
|
-
<Link
|
|
34
|
-
to="/posts/$postId"
|
|
35
|
-
params={{ postId: p.id }}
|
|
36
|
-
style={{ textDecoration: "none", color: "#374151" }}
|
|
37
|
-
activeProps={{ style: { fontWeight: "bold", color: "#111" } }}
|
|
38
|
-
>
|
|
39
|
-
{p.title}
|
|
40
|
-
</Link>
|
|
41
|
-
</li>
|
|
42
|
-
))}
|
|
43
|
-
</ul>
|
|
44
|
-
</div>
|
|
45
|
-
<div style={{ flex: 1 }}>
|
|
46
|
-
<Outlet />
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const postsRoute = createRoute({
|
|
53
|
-
getParentRoute: () => rootRoute,
|
|
54
|
-
path: "/posts",
|
|
55
|
-
component: PostsLayout,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// ── Posts index (/posts/) ──
|
|
59
|
-
|
|
60
|
-
export const postsIndexRoute = createRoute({
|
|
61
|
-
getParentRoute: () => postsRoute,
|
|
62
|
-
path: "/",
|
|
63
|
-
component: () => (
|
|
64
|
-
<p style={{ color: "#6b7280" }}>← Select a post from the sidebar</p>
|
|
65
|
-
),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// ── Post detail (/posts/$postId) ──
|
|
69
|
-
|
|
70
|
-
function PostDetail() {
|
|
71
|
-
const { postId } = postDetailRoute.useParams();
|
|
72
|
-
const { data: post } = useQuery(getPost, postId);
|
|
73
|
-
|
|
74
|
-
if (!post) return <p>Loading...</p>;
|
|
75
|
-
return (
|
|
76
|
-
<div>
|
|
77
|
-
<h2>{post.title}</h2>
|
|
78
|
-
<p style={{ color: "#6b7280" }}>
|
|
79
|
-
by{" "}
|
|
80
|
-
<Link to="/users/$username" params={{ username: post.author }}>
|
|
81
|
-
{post.author}
|
|
82
|
-
</Link>
|
|
83
|
-
</p>
|
|
84
|
-
<p>{post.body}</p>
|
|
85
|
-
<div>
|
|
86
|
-
{post.tags.map((tag) => (
|
|
87
|
-
<span key={tag} style={styles.tag}>
|
|
88
|
-
{tag}
|
|
89
|
-
</span>
|
|
90
|
-
))}
|
|
91
|
-
</div>
|
|
92
|
-
</div>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const postDetailRoute = createRoute({
|
|
97
|
-
getParentRoute: () => postsRoute,
|
|
98
|
-
path: "$postId",
|
|
99
|
-
component: PostDetail,
|
|
100
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { createRoute, Link, useQuery } from "@evjs/client";
|
|
2
|
-
import { getPosts } from "../api/data.server";
|
|
3
|
-
import { rootRoute } from "./__root";
|
|
4
|
-
|
|
5
|
-
const styles = {
|
|
6
|
-
card: {
|
|
7
|
-
border: "1px solid #e5e7eb",
|
|
8
|
-
borderRadius: 8,
|
|
9
|
-
padding: "1rem",
|
|
10
|
-
marginBottom: "0.75rem",
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function SearchPage() {
|
|
15
|
-
const { q } = searchRoute.useSearch();
|
|
16
|
-
const { data: results } = useQuery(getPosts, q || undefined);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div>
|
|
20
|
-
<h2>Search</h2>
|
|
21
|
-
<form
|
|
22
|
-
onSubmit={(e) => {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
const form = new FormData(e.currentTarget);
|
|
25
|
-
const q = form.get("q") as string;
|
|
26
|
-
window.location.search = `?q=${encodeURIComponent(q)}`;
|
|
27
|
-
}}
|
|
28
|
-
>
|
|
29
|
-
<input
|
|
30
|
-
name="q"
|
|
31
|
-
defaultValue={q}
|
|
32
|
-
placeholder="Search posts..."
|
|
33
|
-
style={{
|
|
34
|
-
padding: "0.5rem",
|
|
35
|
-
width: 300,
|
|
36
|
-
borderRadius: 4,
|
|
37
|
-
border: "1px solid #d1d5db",
|
|
38
|
-
}}
|
|
39
|
-
/>
|
|
40
|
-
</form>
|
|
41
|
-
<div style={{ marginTop: "1rem" }}>
|
|
42
|
-
{q && <p style={{ color: "#6b7280" }}>Results for "{q}":</p>}
|
|
43
|
-
{results?.map((post) => (
|
|
44
|
-
<div key={post.id} style={styles.card}>
|
|
45
|
-
<Link
|
|
46
|
-
to="/posts/$postId"
|
|
47
|
-
params={{ postId: post.id }}
|
|
48
|
-
style={{ textDecoration: "none", color: "#111" }}
|
|
49
|
-
>
|
|
50
|
-
<strong>{post.title}</strong>
|
|
51
|
-
</Link>
|
|
52
|
-
<p
|
|
53
|
-
style={{ margin: "0.25rem 0 0", color: "#6b7280", fontSize: 14 }}
|
|
54
|
-
>
|
|
55
|
-
{post.body}
|
|
56
|
-
</p>
|
|
57
|
-
</div>
|
|
58
|
-
))}
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const searchRoute = createRoute({
|
|
65
|
-
getParentRoute: () => rootRoute,
|
|
66
|
-
path: "/search",
|
|
67
|
-
validateSearch: (search: Record<string, unknown>) => ({
|
|
68
|
-
q: (search.q as string) || "",
|
|
69
|
-
}),
|
|
70
|
-
component: SearchPage,
|
|
71
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createRoute, Link, useQuery } from "@evjs/client";
|
|
2
|
-
import { getUser } from "../api/data.server";
|
|
3
|
-
import { rootRoute } from "./__root";
|
|
4
|
-
|
|
5
|
-
const styles = {
|
|
6
|
-
card: { border: "1px solid #e5e7eb", borderRadius: 8, padding: "1rem" },
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function UserProfile() {
|
|
10
|
-
const { username } = userRoute.useParams();
|
|
11
|
-
const { data: user } = useQuery(getUser, username);
|
|
12
|
-
|
|
13
|
-
if (!user) return <p>Loading...</p>;
|
|
14
|
-
return (
|
|
15
|
-
<div style={styles.card}>
|
|
16
|
-
<h2>{user.name}</h2>
|
|
17
|
-
<p style={{ color: "#6b7280" }}>@{user.username}</p>
|
|
18
|
-
<p>{user.bio}</p>
|
|
19
|
-
<Link to="/posts">← Back to posts</Link>
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const userRoute = createRoute({
|
|
25
|
-
getParentRoute: () => rootRoute,
|
|
26
|
-
path: "/users/$username",
|
|
27
|
-
component: UserProfile,
|
|
28
|
-
});
|