RoutingNG: Fix infinite loop caused by history state not being cleaned up (#31952)

* Fix infinite loop caused by history state not being cleaned up

* Ude forceRouteReload counter instead of bool flag

* Review fix
This commit is contained in:
Dominik Prokop
2021-03-16 09:27:32 +01:00
committed by GitHub
parent 7552711660
commit 0d92425bb8
6 changed files with 23 additions and 62 deletions

View File

@@ -11,7 +11,7 @@ import { config } from '../config';
export interface LocationService {
partial: (query: Record<string, any>, replace?: boolean) => void;
push: (location: H.Path | H.LocationDescriptor<any>) => void;
replace: (location: H.Path | H.LocationDescriptor<any>, forceRouteReload?: boolean) => void;
replace: (location: H.Path | H.LocationDescriptor<any>) => void;
reload: () => void;
getLocation: () => H.Location;
getHistory: () => H.History;
@@ -95,23 +95,15 @@ export class HistoryWrapper implements LocationService {
this.history.push(location);
}
replace(location: H.Path | H.LocationDescriptor, forceRouteReload?: boolean) {
const state = forceRouteReload ? { forceRouteReload: true } : undefined;
if (typeof location === 'string') {
this.history.replace(location, state);
} else {
this.history.replace({
...location,
state,
});
}
replace(location: H.Path | H.LocationDescriptor) {
this.history.replace(location);
}
reload() {
const prevState = (this.history.location.state as any)?.routeReloadCounter;
this.history.replace({
...this.history.location,
state: { forceRouteReload: true },
state: { routeReloadCounter: prevState ? prevState + 1 : 1 },
});
}