title: Angular2 check if name exists in the url
body: <p>I'm still learning angular and typescript so excuse me for the stupid question...</p>
  
  <p>I have a list with actors, once clicked on an actor it redirects you to a detail page. The url for the list looks like this</p>
  
  <pre><code>localhost:4200/actors
  </code></pre>
  
  <p>so once clicked on an actor it's like this</p>
  
  <pre><code>localhost:4200/actors/Jonas
  </code></pre>
  
  <p>However i'm trying to check if the chosen actor actually exists. So if the user manually types a random name in the url it redirects back to the /actors page instead of displaying a blank page.</p>
  
  <p>My component looks like this:</p>
  
  <pre><code>actor: Actor;
  constructor(
      private actorService: ActorService,
      private route: ActivatedRoute,
      private location: Location
  ) {}
  ngOnInit(): void {
      this.route.params.subscribe(() =&gt; {
          if (/* code to check if actor.name exists in the url */ ) {
              this.route.paramMap.switchMap((params: ParamMap) =&gt;
                  this.actorService.getActor(params.get('name')!))
                  .subscribe(actor =&gt; this.actor = actor);
          }else {
              this.location.go('/actors');
          }
      });
  }
  </code></pre>
  
  <p>anyone an idea how i achieve this?</p>