Angular 2 Check if query parameter exists in the url
I would say using: ngOnInit() { if (this.route.snapshot.queryParams[‘id’]) { //do your stuff. example: console.log(‘id: ‘, this.route.snapshot.queryParams[‘id’]); } } would be sufficient. Don’t forget to initialize private route: ActivatedRoute in constructor and import { ActivatedRoute } from ‘@angular/router’; Since you only need to check if it exists or not. If it does your stuff would occur, … Read more