title: Angular 2: Select a link by default when page loads after login
body: <p>How can I select a link by default when home page loads after login? There are a couple of links on the sidebar and I want one of the link to selected by default.<br/>
  All these links have <code>click</code> functions associated with them. I want <code>click</code> function to be instantiated when page loads.
  <br/>
  I have tried:</p>
  
  <pre><code>ngAfterViewInit() {
      document.getElementById('focusLink').focus();
    }
  </code></pre>
  
  <p>But it does not <code>selects</code> the link and calls the function.<br/>
  It is dynamic menu which changes based on who is logged in. I wouldn't know which url to call when page loads. <br/>The only thing I know is that first link of menu should be selected by default. All the links call to the same function based on the url associated with them.
  <br/>
  Each sidebar link has a route associated with it. Onlick calls follwoing function:</p>
  
  <pre><code>private subMenuClick(link) {
      this.topBarHeading = link.heading;
      //load the url
      if (!link.sub) {
        this.router.navigateByUrl(link.href);
        this.routeUrl = link.href;
        return;
      }
      //open close menu
      this.mainNavigation.forEach(el =&gt; {
        if ((el !== link) &amp;&amp; el.open &amp;&amp; !el.sub.indexOf(link)) {
          el.open = false;
        }
      });
  
      link.open = !link.open;
      return false;
    };
  </code></pre>