Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 802953f

Browse files
committed
fix(operators): Redirect for not found operator
1 parent 6e41260 commit 802953f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/app/operators/components/operator/operator.component.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Inject,
77
InjectionToken
88
} from '@angular/core';
9-
import { ActivatedRoute } from '@angular/router';
9+
import { Router, ActivatedRoute } from '@angular/router';
1010
import { OperatorDoc } from '../../../../operator-docs/operator.model';
1111
import 'rxjs/add/operator/pluck';
1212

@@ -24,18 +24,26 @@ export class OperatorComponent implements OnInit {
2424
private readonly baseSpecUrl = 'http://reactivex.io/rxjs/test-file/spec-js/operators';
2525

2626
constructor(
27+
private _router: Router,
2728
private _activatedRoute: ActivatedRoute,
2829
@Inject(OPERATOR_TOKEN) public operators: OperatorDoc[]
2930
) {}
3031

3132
ngOnInit() {
3233
this._activatedRoute.params.pluck('operator').subscribe((name: string) => {
33-
this.operator = this.operators.filter(
34-
(operator: OperatorDoc) => operator.name === name
35-
)[0];
34+
this.operator =
35+
this.operators.filter(
36+
(operator: OperatorDoc) => operator.name === name
37+
)[0] || this.notfound();
3638
});
3739
}
3840

41+
notfound() {
42+
console.log('not found');
43+
this._router.navigate(['/operators']);
44+
return {};
45+
}
46+
3947
get operatorName() {
4048
return this.operator.name;
4149
}

0 commit comments

Comments
 (0)