Question: I'm using angular 5.0.3, I would like to start my application with a bunch of query parameters like `/app?param1=hallo&param2=123`. Every tip given in [How to get query params from url in Angular 2?](https://stackoverflow.com/questions/35688084/how-get-query-params-from-url-in-angular2/37962626) does not work for me.

Any ideas how to get query parameters work?

```
private getQueryParameter(key: string): string {
  const parameters = new URLSearchParams(window.location.search);
  return parameters.get(key);
}

```

This private function helps me to get my parameters, but I don't think it is the right way in new Angular environment.

[update:]
My main app looks like

```
@Component({...})
export class AppComponent implements OnInit {

  constructor(private route: ActivatedRoute) {}

  ngOnInit(): void {
    // would like to get query parameters here...
    // this.route...
  }
}

```

Answer: 
Angular [Router](https://angular.io/api/router/Router) provides method [*parseUrl(url: string)*](https://angular.io/api/router/Router#parseUrl) that parses url into [UrlTree](https://angular.io/api/router/UrlTree). One of the properties of UrlTree are queryParams. So you can do sth like:

```
this.router.parseUrl(this.router.url).queryParams[key] || '';

```
Just stumbled upon the same problem and most answers here seem to only solve it for Angular internal routing, and then some of them for route parameters which is not the same as request parameters. 

I am guessing that I have a similar use case to the original question by Lars.

For me the use case is e.g. referral tracking:

Angular running on `mycoolpage.com`, with hash routing, so `mycoolpage.com` redirects to `mycoolpage.com/#/`. For referral, however, a link such as `mycoolpage.com?referrer=foo` should also be usable. Unfortunately, Angular immediately strips the request parameters, going directly to `mycoolpage.com/#/`. 

Any kind of 'trick' with using an empty component + AuthGuard and getting `queryParams` or `queryParamMap` did, unfortunately, not work for me. They were always empty.

My hacky solution ended up being to handle this in a small script in `index.html` which gets the full URL, **with** request parameters. I then get the request param value via string manipulation and set it on window object. A separate service then handles getting the id from the window object.

**index.html script**

```
const paramIndex = window.location.href.indexOf('referrer=');
if (!window.myRef && paramIndex > 0) {
  let param = window.location.href.substring(paramIndex);
  param = param.split('&')[0];
  param = param.substr(param.indexOf('=')+1);
  window.myRef = param;
}

```

**Service**

```
declare var window: any;

@Injectable()
export class ReferrerService {

  getReferrerId() {
    if (window.myRef) {
      return window.myRef;
    }
    return null;
  }
}

```