Skip to content

Commit 80702bf

Browse files
committed
fix(reactant-share): fix router sync up
1 parent 708e8a2 commit 80702bf

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/reactant-share/src/modules/router.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ class ReactantRouter extends BaseReactantRouter {
8787
action.payload.isFirstRendering
8888
) {
8989
const router = this._routers[this.portDetector.name];
90-
if (
91-
router &&
92-
this.history.createHref(router.location) !==
93-
this.history.createHref(this.router!.location)
94-
) {
90+
if (router && this.compareRouter(router, this.router!)) {
9591
stopWatching();
9692
// router reducer @@router/LOCATION_CHANGE event and syncFullState event The events may be out of order, so we re-check route consistency after synchronizing the state.
9793
this.history.replace(router.location);
@@ -339,6 +335,17 @@ class ReactantRouter extends BaseReactantRouter {
339335
};
340336
}
341337

338+
compareRouter(router1: RouterState, router2: RouterState) {
339+
return (
340+
this.history.createHref(router1.location) !==
341+
this.history.createHref(router2.location) ||
342+
JSON.stringify(router1.location.state) !==
343+
JSON.stringify(router2.location.state) ||
344+
JSON.stringify((router1.location as any).query) !==
345+
JSON.stringify((router2.location as any).query)
346+
);
347+
}
348+
342349
/**
343350
* The timestamp of the last routing.
344351
*/
@@ -359,10 +366,7 @@ class ReactantRouter extends BaseReactantRouter {
359366
if (name === this.portDetector.name) {
360367
if (this.portDetector.isWorkerMode) {
361368
this.dispatchChanged(router);
362-
} else if (
363-
this.history.createHref(router.location) !==
364-
this.history.createHref(this.router!.location)
365-
) {
369+
} else if (this.compareRouter(router, this.router!)) {
366370
this.passiveRoute = true;
367371
this.history.push(router.location);
368372
this.passiveRoute = false;
@@ -405,11 +409,7 @@ class ReactantRouter extends BaseReactantRouter {
405409
)
406410
return;
407411
const route = () => {
408-
if (
409-
this.history &&
410-
this.history.createHref(router.location) !==
411-
this.history.createHref(this.router!.location)
412-
) {
412+
if (this.history && this.compareRouter(router, this.router!)) {
413413
this.passiveRoute = true;
414414
this.history.push(router.location);
415415
this.passiveRoute = false;

0 commit comments

Comments
 (0)