zova-module-a-router 5.0.60 → 5.0.63
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/package.json +3 -3
- package/src/bean/bean.router.ts +32 -5
- package/src/bean/local.router.ts +3 -0
- package/src/config/config.ts +1 -1
- package/src/monkey.ts +6 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-module-a-router",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.63",
|
|
4
4
|
"title": "a-router",
|
|
5
5
|
"zovaModule": {
|
|
6
6
|
"capabilities": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"_prepublishOnly": "npm run tsc:publish"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"vue-router": "^4.
|
|
41
|
+
"vue-router": "^4.4.5"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "200ff5791bd6362080428f5b6c6c8f2a82c7d9d0"
|
|
44
44
|
}
|
package/src/bean/bean.router.ts
CHANGED
|
@@ -26,6 +26,8 @@ export class BeanRouter extends BeanBase {
|
|
|
26
26
|
if (mainRouter) {
|
|
27
27
|
// config.routes
|
|
28
28
|
this._loadConfigRoutes();
|
|
29
|
+
// legacy routes
|
|
30
|
+
this._loadLegacyRoutes();
|
|
29
31
|
} else {
|
|
30
32
|
// emit event
|
|
31
33
|
await this.app.meta.event.emit('a-router:routerGuards', this);
|
|
@@ -68,7 +70,11 @@ export class BeanRouter extends BeanBase {
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
public checkPathValid(to?: { name?: string; path?: string } | string): boolean {
|
|
73
|
+
const _name = to && typeof to === 'object' ? to.name : undefined;
|
|
71
74
|
const _path = to && typeof to === 'object' ? (to.name ?? to.path) : to;
|
|
75
|
+
// legacy
|
|
76
|
+
if (this._findLegacyRoute(_name, _path)) return true;
|
|
77
|
+
// general check
|
|
72
78
|
if (!_path) return true;
|
|
73
79
|
const moduleName = ModuleInfo.parseName(_path);
|
|
74
80
|
if (!moduleName) return true;
|
|
@@ -104,17 +110,17 @@ export class BeanRouter extends BeanBase {
|
|
|
104
110
|
|
|
105
111
|
/** @internal */
|
|
106
112
|
public _registerRoutes(module: IModule) {
|
|
107
|
-
if (!module.resource.routes) return
|
|
113
|
+
if (!module.resource.routes) return;
|
|
108
114
|
for (const route of module.resource.routes) {
|
|
109
|
-
this._registerRoute(
|
|
115
|
+
this._registerRoute(route, module);
|
|
110
116
|
}
|
|
111
117
|
}
|
|
112
118
|
|
|
113
|
-
private _registerRoute(
|
|
119
|
+
private _registerRoute(route: IModuleRoute, module?: IModule) {
|
|
114
120
|
// path
|
|
115
121
|
let path: string | undefined;
|
|
116
122
|
if (route.path !== undefined) {
|
|
117
|
-
if (route.meta?.absolute === true) {
|
|
123
|
+
if (!module || route.meta?.absolute === true) {
|
|
118
124
|
path = route.path;
|
|
119
125
|
} else {
|
|
120
126
|
path = route.path
|
|
@@ -125,7 +131,7 @@ export class BeanRouter extends BeanBase {
|
|
|
125
131
|
// name
|
|
126
132
|
let name: string | undefined;
|
|
127
133
|
if (route.name) {
|
|
128
|
-
if (route.meta?.absolute === true) {
|
|
134
|
+
if (!module || route.meta?.absolute === true) {
|
|
129
135
|
name = String(route.name);
|
|
130
136
|
} else {
|
|
131
137
|
name = `${module.info.relativeName}:${String(route.name)}`;
|
|
@@ -193,6 +199,14 @@ export class BeanRouter extends BeanBase {
|
|
|
193
199
|
}
|
|
194
200
|
}
|
|
195
201
|
|
|
202
|
+
private _loadLegacyRoutes() {
|
|
203
|
+
const legacyRoutes = Cast(this.app.meta).legacyRoutes;
|
|
204
|
+
if (!legacyRoutes) return;
|
|
205
|
+
for (const route of legacyRoutes) {
|
|
206
|
+
this._registerRoute(route);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
196
210
|
private _loadConfigRoute(route: IModuleRoute) {
|
|
197
211
|
this.router.addRoute(route);
|
|
198
212
|
}
|
|
@@ -206,6 +220,19 @@ export class BeanRouter extends BeanBase {
|
|
|
206
220
|
return name ? this.app.config.routes.name[name] : this.app.config.routes.path[path!];
|
|
207
221
|
}
|
|
208
222
|
|
|
223
|
+
/** @internal */
|
|
224
|
+
public _findLegacyRoute(
|
|
225
|
+
name: string | symbol | null | undefined,
|
|
226
|
+
path: string | undefined,
|
|
227
|
+
): IModuleRoute | undefined {
|
|
228
|
+
const legacyRoutes = Cast(this.app.meta).legacyRoutes;
|
|
229
|
+
if (!legacyRoutes) return;
|
|
230
|
+
name = this.getRealRouteName(name);
|
|
231
|
+
return legacyRoutes.find(item => {
|
|
232
|
+
return name ? item.name === name : item.path === path;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
209
236
|
getRealRouteName(name?: string | symbol | null): string | undefined {
|
|
210
237
|
return getRealRouteName(name);
|
|
211
238
|
}
|
package/src/bean/local.router.ts
CHANGED
|
@@ -17,6 +17,9 @@ export class LocalRouter extends BeanRouterBase<ScopeModule> {
|
|
|
17
17
|
match = match.aliasOf;
|
|
18
18
|
} else {
|
|
19
19
|
match = to.matched[to.matched.length - 1];
|
|
20
|
+
// legacy
|
|
21
|
+
const legacyRoute = this.$$router._findLegacyRoute(match?.name, match?.path);
|
|
22
|
+
if (legacyRoute) return;
|
|
20
23
|
// alias
|
|
21
24
|
const configRoute = this.$$router._findConfigRoute(match?.name, match?.path);
|
|
22
25
|
const alias = configRoute?.alias;
|
package/src/config/config.ts
CHANGED
package/src/monkey.ts
CHANGED
|
@@ -38,18 +38,18 @@ export class Monkey extends BeanSimple implements IMonkeySystem, IMonkeyModule,
|
|
|
38
38
|
return this._beanRouter;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async appInitialize(
|
|
41
|
+
async appInitialize() {
|
|
42
42
|
// router
|
|
43
|
-
this.localRouter = await bean._newBean(LocalRouter, false);
|
|
43
|
+
this.localRouter = await this.bean._newBean(LocalRouter, false);
|
|
44
44
|
}
|
|
45
|
-
async appInitialized(
|
|
45
|
+
async appInitialized() {
|
|
46
46
|
// component default
|
|
47
|
-
const scope: ScopeModule = await bean.getScope(__ThisModule__);
|
|
48
|
-
this._beanComponentDefault = await bean.getScope(scope.config.defaultComponent);
|
|
47
|
+
const scope: ScopeModule = await this.bean.getScope(__ThisModule__);
|
|
48
|
+
this._beanComponentDefault = await this.bean.getScope(scope.config.defaultComponent);
|
|
49
49
|
// emit event
|
|
50
50
|
await this.app.meta.event.emit('a-router:routerGuards', this._beanRouter);
|
|
51
51
|
}
|
|
52
|
-
async appReady(
|
|
52
|
+
async appReady() {
|
|
53
53
|
// use router
|
|
54
54
|
this.app.vue.use(this._beanRouter);
|
|
55
55
|
// ssr
|