@@ -20,12 +20,10 @@ import type {
20
20
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
21
21
class TaskType {
22
22
public static outside = 'outside' ;
23
- public static envBridge = 'envBridge' ;
24
- public static applyRoute = 'applyRoute' ;
25
- public static push = 'push' ;
26
- public static replace = 'replace' ;
27
- public static open = 'open' ;
28
- public static reload = 'reload' ;
23
+ public static callBridge = 'callBridge' ;
24
+ public static applyApp = 'applyApp' ;
25
+ public static applyNavigation = 'applyNavigation' ;
26
+ public static applyWindow = 'applyWindow' ;
29
27
}
30
28
31
29
export class Router {
@@ -36,14 +34,13 @@ export class Router {
36
34
private _microApp : MicroApp = new MicroApp ( ) ;
37
35
38
36
private _tasks = {
39
- // 检查是否是外部链接
40
37
[ TaskType . outside ] : ( ctx : RouteTaskContext ) => {
41
38
if ( ctx . to . matched . length === 0 ) {
42
39
ctx . options . onOpen ( ctx . to ) ;
43
40
return ctx . finish ( ) ;
44
41
}
45
42
} ,
46
- [ TaskType . envBridge ] : async ( ctx : RouteTaskContext ) => {
43
+ [ TaskType . callBridge ] : async ( ctx : RouteTaskContext ) => {
47
44
const { to } = ctx ;
48
45
if ( ! to . config || ! to . config . env ) {
49
46
return ;
@@ -64,56 +61,48 @@ export class Router {
64
61
ctx . finish ( ) ;
65
62
}
66
63
} ,
67
- // 应用当前的 URL
68
- [ TaskType . applyRoute ] : ( ctx : RouteTaskContext ) => {
64
+ [ TaskType . applyApp ] : ( ctx : RouteTaskContext ) => {
69
65
this . _route = ctx . to ;
70
- this . _microApp . _update ( this ) ;
66
+ this . _microApp . _update (
67
+ this ,
68
+ ctx . navigationType === NavigationType . reload
69
+ ) ;
71
70
} ,
72
- [ TaskType . push ] : ( ctx : RouteTaskContext ) => {
71
+ [ TaskType . applyNavigation ] : ( ctx : RouteTaskContext ) => {
73
72
this . _navigation . push ( ctx . to ) ;
74
73
ctx . finish ( ) ;
75
74
} ,
76
- [ TaskType . replace ] : ( ctx : RouteTaskContext ) => {
77
- this . _navigation . push ( ctx . to ) ;
78
- ctx . finish ( ) ;
79
- } ,
80
- [ TaskType . open ] : ( ctx : RouteTaskContext ) => {
75
+ [ TaskType . applyWindow ] : ( ctx : RouteTaskContext ) => {
81
76
ctx . options . onOpen ( ctx . to ) ;
82
77
ctx . finish ( ) ;
83
- } ,
84
- [ TaskType . reload ] : ( ctx : RouteTaskContext ) => {
85
- this . _microApp . _update ( this ) ;
86
- ctx . finish ( ) ;
87
78
}
88
79
} satisfies Record < string , RouteTaskCallback > ;
89
80
private _taskMaps = {
90
81
[ NavigationType . push ] : [
91
82
TaskType . outside ,
92
- TaskType . envBridge ,
93
- TaskType . applyRoute ,
94
- TaskType . push
83
+ TaskType . callBridge ,
84
+ TaskType . applyApp ,
85
+ TaskType . applyNavigation
95
86
] ,
96
87
[ NavigationType . replace ] : [
97
88
TaskType . outside ,
98
- TaskType . envBridge ,
99
- TaskType . applyRoute ,
100
- TaskType . replace
89
+ TaskType . applyApp ,
90
+ TaskType . applyNavigation
101
91
] ,
102
92
[ NavigationType . openWindow ] : [
103
93
TaskType . outside ,
104
- TaskType . envBridge ,
105
- TaskType . open
94
+ TaskType . callBridge ,
95
+ TaskType . applyWindow
106
96
] ,
107
97
[ NavigationType . replaceWindow ] : [
108
98
TaskType . outside ,
109
- TaskType . envBridge ,
110
- TaskType . open
99
+ TaskType . applyWindow
111
100
] ,
112
- [ NavigationType . reload ] : [ TaskType . outside , TaskType . reload ] ,
113
- [ NavigationType . back ] : [ TaskType . outside ] ,
114
- [ NavigationType . go ] : [ TaskType . outside ] ,
115
- [ NavigationType . forward ] : [ TaskType . outside ] ,
116
- [ NavigationType . popstate ] : [ TaskType . outside ]
101
+ [ NavigationType . reload ] : [ TaskType . outside , TaskType . applyApp ] ,
102
+ [ NavigationType . back ] : [ TaskType . applyApp ] ,
103
+ [ NavigationType . go ] : [ TaskType . applyApp ] ,
104
+ [ NavigationType . forward ] : [ TaskType . applyApp ] ,
105
+ [ NavigationType . popstate ] : [ TaskType . applyApp ]
117
106
} satisfies Record < string , TaskType [ ] > ;
118
107
119
108
public get route ( ) {
0 commit comments