Skip to content

Commit 92895f8

Browse files
committed
chore: fix the navigation
When a resource is added or modified, it is not always returned to the correct page. The editor now uses the previous url to redirect. * Closes rero/rero-ils#3628. Co-Authored-by: Bertrand Zuchuat <[email protected]>
1 parent 71e6a2e commit 92895f8

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

projects/rero/ng-core/src/lib/record/editor/editor.component.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { Location } from '@angular/common';
1818
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
1919
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
20-
import { ActivatedRoute } from '@angular/router';
20+
import { ActivatedRoute, Router } from '@angular/router';
2121
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
2222
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
2323
import { TranslateService } from '@ngx-translate/core';
@@ -138,6 +138,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
138138
// Observable of hidden fields
139139
private _hiddenFieldsSubject: BehaviorSubject<FormlyFieldConfig[]> = new BehaviorSubject([]);
140140

141+
// Previous Url for navigation
142+
private previousUrl?: string = undefined;
143+
141144
// current list of hidden fields
142145
public get hiddenFields$(): Observable<any[]> {
143146
return this._hiddenFieldsSubject.asObservable();
@@ -176,6 +179,7 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
176179
* @param modalService BsModalService.
177180
* @param routeCollectionService RouteCollectionService
178181
* @param loggerService LoggerService
182+
* @param router Router
179183
*/
180184
constructor(
181185
protected formlyJsonschema: FormlyJsonschema,
@@ -188,10 +192,12 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
188192
protected location: Location,
189193
protected modalService: BsModalService,
190194
protected routeCollectionService: RouteCollectionService,
191-
protected loggerService: LoggerService
195+
protected loggerService: LoggerService,
196+
protected router: Router
192197
) {
193198
super();
194199
this.form = new UntypedFormGroup({});
200+
this.previousUrl = this.router.getCurrentNavigation()?.previousNavigation?.extractedUrl?.toString();
195201
}
196202

197203
/**
@@ -576,13 +582,17 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
576582
this.translateService.instant(result.message),
577583
this.translateService.instant(this.recordType)
578584
);
579-
this.recordUiService.redirectAfterSave(
580-
result.record.id,
581-
result.record,
582-
this.recordType,
583-
result.action,
584-
this.route
585-
);
585+
if (this.previousUrl) {
586+
this.router.navigateByUrl(this.previousUrl);
587+
} else {
588+
this.recordUiService.redirectAfterSave(
589+
result.record.id,
590+
result.record,
591+
this.recordType,
592+
result.action,
593+
this.route
594+
);
595+
}
586596
this.loadingChange.emit(true);
587597
});
588598
}

0 commit comments

Comments
 (0)