|
1 | | -import { Component, OnInit } from '@angular/core'; |
2 | | -import { Observable } from 'rxjs'; |
3 | | -import { switchMap } from 'rxjs/operators'; |
4 | | -import { LocationService } from 'app/shared/location.service'; |
5 | | -import { SearchResults } from 'app/search/interfaces'; |
6 | | -import { SearchService } from 'app/search/search.service'; |
| 1 | +import {Component, OnInit} from '@angular/core'; |
| 2 | +import {Observable} from 'rxjs'; |
| 3 | +import {switchMap} from 'rxjs/operators'; |
| 4 | +import {LocationService} from 'app/shared/location.service'; |
| 5 | +import {SearchResults} from 'app/search/interfaces'; |
| 6 | +import {SearchService} from 'app/search/search.service'; |
7 | 7 |
|
8 | 8 | @Component({ |
9 | 9 | selector: 'aio-file-not-found-search', |
10 | | - template: |
11 | | - `<div class="alert is-helpful"> |
| 10 | + template: `<div class="alert is-helpful"> |
| 11 | + <p *ngIf="redirectedFrom"> |
| 12 | + You were redirected from the Angular v{{ redirectedFrom }} documentation, but this page doesn't |
| 13 | + exist in this version. |
| 14 | + </p> |
12 | 15 | <p>Let's see if any of these search results help...</p> |
13 | | - </div> |
14 | | - <aio-search-results class="embedded" [searchResults]="searchResults | async"></aio-search-results>` |
| 16 | + </div> |
| 17 | + <aio-search-results |
| 18 | + class="embedded" |
| 19 | + [searchResults]="searchResults | async" |
| 20 | + ></aio-search-results>`, |
15 | 21 | }) |
16 | 22 | export class FileNotFoundSearchComponent implements OnInit { |
17 | 23 | searchResults: Observable<SearchResults>; |
| 24 | + redirectedFrom: number | null = null; |
18 | 25 | constructor(private location: LocationService, private search: SearchService) {} |
19 | 26 |
|
20 | 27 | ngOnInit() { |
21 | 28 | this.searchResults = this.location.currentPath.pipe(switchMap(path => { |
22 | 29 | const query = path.split(/\W+/).join(' '); |
23 | 30 | return this.search.search(query); |
24 | 31 | })); |
| 32 | + |
| 33 | + this.redirectedFrom = this.getRedirectedFromParam(); |
| 34 | + } |
| 35 | + |
| 36 | + private getRedirectedFromParam(): number | null { |
| 37 | + const urlSearchParams = new URLSearchParams(window.location.search); |
| 38 | + const redirected_from = urlSearchParams.get('redirected_from'); |
| 39 | + return redirected_from ? parseInt(redirected_from, 10) : null; |
25 | 40 | } |
26 | 41 | } |
0 commit comments