in Angular by
Q:
Demonstrate navigating between different routes in an Angular application.

1 Answer

0 votes
by
Following code demonstrates how to navigate between different routes in an Angular app dubbed “Some Search App”:

import {Router} from "@angular/router";

.

.

.

@Component({

  selector: 'app-header',

  template: `

<nav class="navbar navbar-light bg-faded">

  <a class="navbar-brand" (click)="goHome()">Some Search App</a>

  <ul class="nav navbar-nav">

    <li class="nav-item">

      <a class="nav-link" (click)="goHome()">Home</a>

    </li>

    <li class="nav-item">

      <a class="nav-link" (click)="goSearch()">Search</a>

    </li>

  </ul>

</nav>

 `

})

class HeaderComponent {

  constructor(private router: Router) {}

  goHome() {

    this.router.navigate(['']);

  }

  goSearch() {

    this.router.navigate(['search']);

  }

}

Related questions

0 votes
0 votes
asked Feb 5 in Angular by SakshiSharma
...