@vureact/compiler-core 1.3.0 → 1.4.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.
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/{chunk-7LBUUA24.js → chunk-IVRFEV6H.js} +852 -779
- package/lib/{chunk-CUCUXW56.esm.js → chunk-NF5BSPYE.esm.js} +813 -740
- package/lib/cli.esm.js +59 -47
- package/lib/cli.js +62 -50
- package/lib/compiler-core.d.cts +1117 -1188
- package/lib/compiler-core.d.ts +1117 -1188
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +99 -91
- package/templates/route-setup-notes.md +0 -192
- package/templates/route-setup-notes.zh.md +0 -192
package/lib/compiler-core.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.4.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
parseOnlyScript,
|
|
19
19
|
parseSFC,
|
|
20
20
|
transform
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-NF5BSPYE.esm.js";
|
|
22
22
|
export {
|
|
23
23
|
BaseCompiler,
|
|
24
24
|
CacheKey,
|
package/lib/compiler-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.4.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkIVRFEV6Hjs = require('./chunk-IVRFEV6H.js');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -33,4 +33,4 @@ var _chunk7LBUUA24js = require('./chunk-7LBUUA24.js');
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
exports.BaseCompiler =
|
|
36
|
+
exports.BaseCompiler = _chunkIVRFEV6Hjs.BaseCompiler; exports.CacheKey = _chunkIVRFEV6Hjs.CacheKey; exports.FileCompiler = _chunkIVRFEV6Hjs.FileCompiler; exports.Helper = _chunkIVRFEV6Hjs.Helper; exports.VuReact = _chunkIVRFEV6Hjs.VuReact; exports.defineConfig = _chunkIVRFEV6Hjs.defineConfig; exports.generate = _chunkIVRFEV6Hjs.generate; exports.generateComponent = _chunkIVRFEV6Hjs.generateComponent; exports.generateOnlyScript = _chunkIVRFEV6Hjs.generateOnlyScript; exports.parse = _chunkIVRFEV6Hjs.parse; exports.parseOnlyScript = _chunkIVRFEV6Hjs.parseOnlyScript; exports.parseSFC = _chunkIVRFEV6Hjs.parseSFC; exports.transform = _chunkIVRFEV6Hjs.transform;
|
package/package.json
CHANGED
|
@@ -1,91 +1,99 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vureact/compiler-core",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "🌀
|
|
5
|
-
"author": "Ruihong Zhong (Ryan John)",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"main": "./lib/compiler-core.js",
|
|
9
|
-
"module": "./lib/compiler-core.esm.js",
|
|
10
|
-
"types": "./lib/compiler-core.d.ts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"types": "./lib/compiler-core.d.ts",
|
|
14
|
-
"import": "./lib/compiler-core.esm.js",
|
|
15
|
-
"require": "./lib/compiler-core.js"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"files": [
|
|
19
|
-
"bin",
|
|
20
|
-
"lib"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"vue
|
|
42
|
-
"react
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"@
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@vureact/compiler-core",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "🌀 Semantic-aware Vue 3 to React 18+ compiler for progressive migration.",
|
|
5
|
+
"author": "Ruihong Zhong (Ryan John)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./lib/compiler-core.js",
|
|
9
|
+
"module": "./lib/compiler-core.esm.js",
|
|
10
|
+
"types": "./lib/compiler-core.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/compiler-core.d.ts",
|
|
14
|
+
"import": "./lib/compiler-core.esm.js",
|
|
15
|
+
"require": "./lib/compiler-core.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin",
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"vue",
|
|
24
|
+
"react",
|
|
25
|
+
"vureact",
|
|
26
|
+
"vue2react",
|
|
27
|
+
"vue-to-react",
|
|
28
|
+
"compiler",
|
|
29
|
+
"transformer",
|
|
30
|
+
"vue3",
|
|
31
|
+
"react18",
|
|
32
|
+
"migration",
|
|
33
|
+
"svelte",
|
|
34
|
+
"typescript",
|
|
35
|
+
"jsx",
|
|
36
|
+
"sfc",
|
|
37
|
+
"veaury",
|
|
38
|
+
"mitosis",
|
|
39
|
+
"vue3-to-react",
|
|
40
|
+
"vue-react",
|
|
41
|
+
"react-vue",
|
|
42
|
+
"vue-in-react",
|
|
43
|
+
"code-migration",
|
|
44
|
+
"framework-migration",
|
|
45
|
+
"vue-migration",
|
|
46
|
+
"react-conversion",
|
|
47
|
+
"single-file-components",
|
|
48
|
+
"progressive-migration",
|
|
49
|
+
"automated-refactoring"
|
|
50
|
+
],
|
|
51
|
+
"homepage": "https://vureact.top",
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://github.com/vureact-js/core.git",
|
|
55
|
+
"directory": "packages/compiler-core"
|
|
56
|
+
},
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/vureact-js/core/issues"
|
|
59
|
+
},
|
|
60
|
+
"bin": {
|
|
61
|
+
"vureact": "./bin/vureact.js"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsup",
|
|
65
|
+
"test": "tsx watch"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"prettier": "^3.0.0"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"prettier": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"@babel/core": "^7.28.5",
|
|
77
|
+
"@babel/generator": "^7.28.3",
|
|
78
|
+
"@babel/parser": "^7.28.4",
|
|
79
|
+
"@babel/traverse": "^7.28.4",
|
|
80
|
+
"@babel/types": "^7.28.4",
|
|
81
|
+
"@vue/compiler-core": "^3.5.22",
|
|
82
|
+
"@vue/compiler-sfc": "^3.5.22",
|
|
83
|
+
"cac": "^6.7.14",
|
|
84
|
+
"chokidar": "^5.0.0",
|
|
85
|
+
"kleur": "^4.1.5",
|
|
86
|
+
"less": "^4.5.1",
|
|
87
|
+
"minimatch": "^10.1.1",
|
|
88
|
+
"ora": "^9.1.0",
|
|
89
|
+
"postcss": "^8.5.6",
|
|
90
|
+
"proper-lockfile": "^4.1.2",
|
|
91
|
+
"sass": "^1.97.3",
|
|
92
|
+
"tsx": "^4.21.0",
|
|
93
|
+
"update-notifier": "^7.3.1",
|
|
94
|
+
"xxhashjs": "^0.2.2"
|
|
95
|
+
},
|
|
96
|
+
"engines": {
|
|
97
|
+
"node": ">=14.0.0"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# Router Adaptation Guide
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
VuReact provides full conversion support for Vue Router, but since routing is an engineering-level context, some manual adjustments are still required after compilation.
|
|
6
|
-
|
|
7
|
-
### Automatically Converted Parts
|
|
8
|
-
|
|
9
|
-
- `<router-link>` → `<RouterLink>`
|
|
10
|
-
- `<router-view>` → `<RouterView>`
|
|
11
|
-
- Routing API calls: `useRouter()`, `useRoute()`, etc.
|
|
12
|
-
- Automatically injects the `@vureact/router` dependency
|
|
13
|
-
|
|
14
|
-
### Parts Requiring Manual Adjustment
|
|
15
|
-
|
|
16
|
-
- Routing configuration file format conversion
|
|
17
|
-
- Entry file rendering method
|
|
18
|
-
- Exclusion configuration setup
|
|
19
|
-
|
|
20
|
-
## Configuration Steps
|
|
21
|
-
|
|
22
|
-
### Step 1: Preparation Before Compilation
|
|
23
|
-
|
|
24
|
-
Ensure your Vue project uses the standard Vue Router configuration.
|
|
25
|
-
|
|
26
|
-
### Step 2: Execute Compilation
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npx vureact build
|
|
30
|
-
|
|
31
|
-
# Or manually configure the npm command
|
|
32
|
-
npm run vr:build
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Step 3: Adjust the Output React Project (Critical Step)
|
|
36
|
-
|
|
37
|
-
#### 3.1 Update the Entry File (src/main.tsx)
|
|
38
|
-
|
|
39
|
-
Example:
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
import { StrictMode } from 'react';
|
|
43
|
-
import { createRoot } from 'react-dom/client';
|
|
44
|
-
import './index.css';
|
|
45
|
-
import router from './router';
|
|
46
|
-
|
|
47
|
-
createRoot(document.getElementById('root')!).render(
|
|
48
|
-
<StrictMode>
|
|
49
|
-
<router.RouterProvider />
|
|
50
|
-
</StrictMode>,
|
|
51
|
-
);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Important Changes**:
|
|
55
|
-
|
|
56
|
-
- Import the Router Provider; there is no need to render `<App />` because `App` should be mounted in the routing configuration.
|
|
57
|
-
|
|
58
|
-
#### 3.2 Convert the Routing Configuration File
|
|
59
|
-
|
|
60
|
-
The actual structure shall be based on the routing configuration output by your project.
|
|
61
|
-
|
|
62
|
-
Rename `src/router/index.ts` to `src/router/index.tsx`.
|
|
63
|
-
|
|
64
|
-
Example:
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
import { createRouter, createWebHashHistory } from '@vureact/router';
|
|
68
|
-
import App from '../App';
|
|
69
|
-
import Dashboard from '../pages/Dashboard';
|
|
70
|
-
import Customers from '../pages/Customers';
|
|
71
|
-
|
|
72
|
-
const router = createRouter({
|
|
73
|
-
history: createWebHashHistory(),
|
|
74
|
-
routes: [
|
|
75
|
-
{
|
|
76
|
-
path: '/',
|
|
77
|
-
component: <App />,
|
|
78
|
-
children: [
|
|
79
|
-
{ path: 'dashboard', component: <Dashboard /> },
|
|
80
|
-
{ path: 'customers', component: <Customers /> },
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
export default router;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**Important Changes**:
|
|
90
|
-
|
|
91
|
-
- File extension: `.ts` → `.tsx`
|
|
92
|
-
- Export the `createRouter` router instance
|
|
93
|
-
- Component syntax: `component: Dashboard` → `component: <Dashboard />`
|
|
94
|
-
- Import method: Keep React component imports
|
|
95
|
-
|
|
96
|
-
#### 3.3 Configure Exclusions
|
|
97
|
-
|
|
98
|
-
Add exclusion configurations to `vureact.config.js` to prevent manually adjusted files from being overwritten during recompilation.
|
|
99
|
-
|
|
100
|
-
If you need to modify these files later, you must **synchronize the changes manually**.
|
|
101
|
-
|
|
102
|
-
Example:
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
export default defineConfig({
|
|
106
|
-
exclude: [
|
|
107
|
-
'src/main.ts',
|
|
108
|
-
'src/router/**', // Exclude the entire routing directory
|
|
109
|
-
],
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Step 4: Verification and Testing
|
|
114
|
-
|
|
115
|
-
1. Install dependencies: `npm install`
|
|
116
|
-
2. Start the project: `npm run dev`
|
|
117
|
-
3. Test route navigation
|
|
118
|
-
4. Verify nested routes
|
|
119
|
-
|
|
120
|
-
## Common Issues
|
|
121
|
-
|
|
122
|
-
### Q1: Blank Page with Console Errors
|
|
123
|
-
|
|
124
|
-
**Possible Cause**: The routing configuration file has not been converted to JSX syntax
|
|
125
|
-
**Solution**:
|
|
126
|
-
|
|
127
|
-
1. Confirm the file extension is `.tsx` or `.jsx`
|
|
128
|
-
2. Check if components use the `<Component />` syntax
|
|
129
|
-
3. Ensure React components are imported correctly
|
|
130
|
-
|
|
131
|
-
### Q2: 404 Error on Route Navigation
|
|
132
|
-
|
|
133
|
-
**Possible Cause**: Incorrect history mode configuration
|
|
134
|
-
**Solution**:
|
|
135
|
-
|
|
136
|
-
- Check `createWebHashHistory` vs `createWebHistory`
|
|
137
|
-
- Verify the base path configuration
|
|
138
|
-
|
|
139
|
-
### Q3: Nested Routes Not Displaying Content
|
|
140
|
-
|
|
141
|
-
**Possible Cause**: Parent component lacks `<RouterView />`
|
|
142
|
-
**Solution**:
|
|
143
|
-
Add a route outlet in the layout component:
|
|
144
|
-
|
|
145
|
-
```vue
|
|
146
|
-
<!-- Original Vue -->
|
|
147
|
-
<template>
|
|
148
|
-
<div>
|
|
149
|
-
<header>...</header>
|
|
150
|
-
<router-view />
|
|
151
|
-
</div>
|
|
152
|
-
</template>
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Q4: Manual Adjustments Overwritten After Compilation
|
|
156
|
-
|
|
157
|
-
**Possible Cause**: Files not added to the `exclude` list
|
|
158
|
-
**Solution**:
|
|
159
|
-
Update `vureact.config.js` and add the adjusted files to the exclusion list.
|
|
160
|
-
|
|
161
|
-
## Best Practices
|
|
162
|
-
|
|
163
|
-
### 1. Routing Configuration Specifications
|
|
164
|
-
|
|
165
|
-
- Export the router instance: `export default createRouter({})`
|
|
166
|
-
- Use named routes: `{ name: 'dashboard', path: '/dashboard', ... }`
|
|
167
|
-
- Configure route lazy loading:
|
|
168
|
-
|
|
169
|
-
```tsx
|
|
170
|
-
const Dashboard = lazy(() => import('../pages/Dashboard'));
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
- Centralize management of route meta fields
|
|
174
|
-
|
|
175
|
-
### 2. File Management Strategy
|
|
176
|
-
|
|
177
|
-
- Manage routing configuration files in a separate directory
|
|
178
|
-
- Separate type definitions into `src/router/types.ts`
|
|
179
|
-
- Unify route guards in `src/router/guards.ts`
|
|
180
|
-
|
|
181
|
-
### 3. Testing Strategy
|
|
182
|
-
|
|
183
|
-
- Unit test routing configurations
|
|
184
|
-
- E2E test route navigation flows
|
|
185
|
-
- Functional comparison testing before and after compilation
|
|
186
|
-
|
|
187
|
-
## Related Resources
|
|
188
|
-
|
|
189
|
-
- [VuReact Official Documentation](https://vureact.top/en)
|
|
190
|
-
- [VuReact Router Official Documentation](https://router.vureact.top/en)
|
|
191
|
-
- [Compilation Issue Feedback and Support](https://github.com/vureact-js/core/issues)
|
|
192
|
-
- [Routing Issue Feedback and Support](https://github.com/vureact-js/vureact-router/issues)
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# 路由适配指南
|
|
2
|
-
|
|
3
|
-
## 概述
|
|
4
|
-
|
|
5
|
-
VuReact 对 Vue Router 提供了完整的转换支持,但由于路由是工程级上下文,编译后仍需要一些人工调整。
|
|
6
|
-
|
|
7
|
-
### 自动转换的部分
|
|
8
|
-
|
|
9
|
-
- `<router-link>` → `<RouterLink>`
|
|
10
|
-
- `<router-view>` → `<RouterView>`
|
|
11
|
-
- 路由API调用:`useRouter()`, `useRoute()`等
|
|
12
|
-
- 自动注入`@vureact/router`依赖
|
|
13
|
-
|
|
14
|
-
### 需要人工调整的部分
|
|
15
|
-
|
|
16
|
-
- 路由配置文件格式转换
|
|
17
|
-
- 入口文件渲染方式
|
|
18
|
-
- 排除配置设置
|
|
19
|
-
|
|
20
|
-
## 配置步骤
|
|
21
|
-
|
|
22
|
-
### 步骤1:编译前的准备
|
|
23
|
-
|
|
24
|
-
确保你的Vue项目使用标准Vue Router配置。
|
|
25
|
-
|
|
26
|
-
### 步骤2:执行编译
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npx vureact build
|
|
30
|
-
|
|
31
|
-
# 或手动配置 npm 命令
|
|
32
|
-
npm run vr:build
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### 步骤3:调整输出的 React 项目(关键步骤)
|
|
36
|
-
|
|
37
|
-
#### 3.1 更新入口文件(src/main.tsx)
|
|
38
|
-
|
|
39
|
-
示例:
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
import { StrictMode } from 'react';
|
|
43
|
-
import { createRoot } from 'react-dom/client';
|
|
44
|
-
import './index.css';
|
|
45
|
-
import router from './router';
|
|
46
|
-
|
|
47
|
-
createRoot(document.getElementById('root')!).render(
|
|
48
|
-
<StrictMode>
|
|
49
|
-
<router.RouterProvider />
|
|
50
|
-
</StrictMode>,
|
|
51
|
-
);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**重要变化**:
|
|
55
|
-
|
|
56
|
-
- 导入路由提供器,不需要渲染 `<App />`,因为 `App` 应该在路由配置中挂载。
|
|
57
|
-
|
|
58
|
-
#### 3.2 转换路由配置文件
|
|
59
|
-
|
|
60
|
-
实际以你项目输出的路由配置结构为准。
|
|
61
|
-
|
|
62
|
-
将 `src/router/index.ts` 改为 `src/router/index.tsx`。
|
|
63
|
-
|
|
64
|
-
示例:
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
import { createRouter, createWebHashHistory } from '@vureact/router';
|
|
68
|
-
import App from '../App';
|
|
69
|
-
import Dashboard from '../pages/Dashboard';
|
|
70
|
-
import Customers from '../pages/Customers';
|
|
71
|
-
|
|
72
|
-
const router = createRouter({
|
|
73
|
-
history: createWebHashHistory(),
|
|
74
|
-
routes: [
|
|
75
|
-
{
|
|
76
|
-
path: '/',
|
|
77
|
-
component: <App />,
|
|
78
|
-
children: [
|
|
79
|
-
{ path: 'dashboard', component: <Dashboard /> },
|
|
80
|
-
{ path: 'customers', component: <Customers /> },
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
export default router;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**重要变化**:
|
|
90
|
-
|
|
91
|
-
- 文件扩展名:`.ts` → `.tsx`
|
|
92
|
-
- 导出 `createRouter` 路由器实例
|
|
93
|
-
- 组件语法:`component: Dashboard` → `component: <Dashboard />`
|
|
94
|
-
- 导入方式:保持React组件导入
|
|
95
|
-
|
|
96
|
-
#### 3.3 配置排除项
|
|
97
|
-
|
|
98
|
-
在 `vureact.config.js` 中添加排除配置,防止重新编译时覆盖手动调整的文件。
|
|
99
|
-
|
|
100
|
-
若后续需要修改这些文件,需**手动同步**变更。
|
|
101
|
-
|
|
102
|
-
示例:
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
export default defineConfig({
|
|
106
|
-
exclude: [
|
|
107
|
-
'src/main.ts',
|
|
108
|
-
'src/router/**', // 排除整个路由目录
|
|
109
|
-
],
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### 步骤4:验证与测试
|
|
114
|
-
|
|
115
|
-
1. 安装依赖:`npm install`
|
|
116
|
-
2. 启动项目:`npm run dev`
|
|
117
|
-
3. 测试路由跳转
|
|
118
|
-
4. 验证嵌套路由
|
|
119
|
-
|
|
120
|
-
## 常见问题
|
|
121
|
-
|
|
122
|
-
### Q1: 页面空白,控制台报错
|
|
123
|
-
|
|
124
|
-
**可能原因**:路由配置文件未转换为JSX语法
|
|
125
|
-
**解决方案**:
|
|
126
|
-
|
|
127
|
-
1. 确认文件扩展名为`.tsx`或`.jsx`
|
|
128
|
-
2. 检查组件是否使用`<Component />`语法
|
|
129
|
-
3. 确保正确导入React组件
|
|
130
|
-
|
|
131
|
-
### Q2: 路由跳转404
|
|
132
|
-
|
|
133
|
-
**可能原因**:历史模式配置错误
|
|
134
|
-
**解决方案**:
|
|
135
|
-
|
|
136
|
-
- 检查`createWebHashHistory` vs `createWebHistory`
|
|
137
|
-
- 确认base路径配置
|
|
138
|
-
|
|
139
|
-
### Q3: 嵌套路由不显示内容
|
|
140
|
-
|
|
141
|
-
**可能原因**:父组件缺少`<RouterView />`
|
|
142
|
-
**解决方案**:
|
|
143
|
-
在布局组件中添加路由出口:
|
|
144
|
-
|
|
145
|
-
```vue
|
|
146
|
-
<!-- Vue原版 -->
|
|
147
|
-
<template>
|
|
148
|
-
<div>
|
|
149
|
-
<header>...</header>
|
|
150
|
-
<router-view />
|
|
151
|
-
</div>
|
|
152
|
-
</template>
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Q4: 编译后手动调整被覆盖
|
|
156
|
-
|
|
157
|
-
**可能原因**:未将文件加入`exclude`列表
|
|
158
|
-
**解决方案**:
|
|
159
|
-
更新`vureact.config.js`,将调整过的文件加入排除列表。
|
|
160
|
-
|
|
161
|
-
## 最佳实践
|
|
162
|
-
|
|
163
|
-
### 1. 路由配置规范
|
|
164
|
-
|
|
165
|
-
- 导出路由器实例:`export default createRouter({})`
|
|
166
|
-
- 使用命名路由:`{ name: 'dashboard', path: '/dashboard', ... }`
|
|
167
|
-
- 配置路由懒加载:
|
|
168
|
-
|
|
169
|
-
```tsx
|
|
170
|
-
const Dashboard = lazy(() => import('../pages/Dashboard'));
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
- 统一管理路由meta字段
|
|
174
|
-
|
|
175
|
-
### 2. 文件管理策略
|
|
176
|
-
|
|
177
|
-
- 路由配置文件单独目录管理
|
|
178
|
-
- 类型定义分离到`src/router/types.ts`
|
|
179
|
-
- 路由守卫统一在`src/router/guards.ts`
|
|
180
|
-
|
|
181
|
-
### 3. 测试策略
|
|
182
|
-
|
|
183
|
-
- 单元测试路由配置
|
|
184
|
-
- E2E测试路由跳转流程
|
|
185
|
-
- 编译前后功能对比测试
|
|
186
|
-
|
|
187
|
-
## 相关资源
|
|
188
|
-
|
|
189
|
-
- [VuReact 官方文档](https://vureact.top)
|
|
190
|
-
- [VuReact Router 官方文档](https://router.vureact.top)
|
|
191
|
-
- [编译问题反馈与支持](https://github.com/vureact-js/core/issues)
|
|
192
|
-
- [路由问题反馈与支持](https://github.com/vureact-js/vureact-router/issues)
|