17
17
import { Location } from '@angular/common' ;
18
18
import { Component , EventEmitter , Input , OnChanges , OnDestroy , OnInit , Output , SimpleChanges , ViewEncapsulation } from '@angular/core' ;
19
19
import { UntypedFormControl , UntypedFormGroup } from '@angular/forms' ;
20
- import { ActivatedRoute } from '@angular/router' ;
20
+ import { ActivatedRoute , Router } from '@angular/router' ;
21
21
import { FormlyFieldConfig , FormlyFormOptions } from '@ngx-formly/core' ;
22
22
import { FormlyJsonschema } from '@ngx-formly/core/json-schema' ;
23
23
import { TranslateService } from '@ngx-translate/core' ;
@@ -138,6 +138,9 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
138
138
// Observable of hidden fields
139
139
private _hiddenFieldsSubject : BehaviorSubject < FormlyFieldConfig [ ] > = new BehaviorSubject ( [ ] ) ;
140
140
141
+ // Previous Url for navigation
142
+ private previousUrl ?: string = undefined ;
143
+
141
144
// current list of hidden fields
142
145
public get hiddenFields$ ( ) : Observable < any [ ] > {
143
146
return this . _hiddenFieldsSubject . asObservable ( ) ;
@@ -176,6 +179,7 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
176
179
* @param modalService BsModalService.
177
180
* @param routeCollectionService RouteCollectionService
178
181
* @param loggerService LoggerService
182
+ * @param router Router
179
183
*/
180
184
constructor (
181
185
protected formlyJsonschema : FormlyJsonschema ,
@@ -188,10 +192,12 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
188
192
protected location : Location ,
189
193
protected modalService : BsModalService ,
190
194
protected routeCollectionService : RouteCollectionService ,
191
- protected loggerService : LoggerService
195
+ protected loggerService : LoggerService ,
196
+ protected router : Router
192
197
) {
193
198
super ( ) ;
194
199
this . form = new UntypedFormGroup ( { } ) ;
200
+ this . previousUrl = this . router . getCurrentNavigation ( ) . previousNavigation ?. extractedUrl ?. toString ( ) ;
195
201
}
196
202
197
203
/**
@@ -576,13 +582,17 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
576
582
this . translateService . instant ( result . message ) ,
577
583
this . translateService . instant ( this . recordType )
578
584
) ;
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
+ }
586
596
this . loadingChange . emit ( true ) ;
587
597
} ) ;
588
598
}
0 commit comments