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

▼ Show 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']);

  }

}
Angular JS
Learn More with Madanswer

Related questions

+1 vote
asked Jan 15, 2020 in Angular by rahuljain1
...