how to navigate from one page to another in angular code example

Example 1: how to navigate from one page to another in angular

const routes: Routes = [
  { path:'', component:LoginComponent},
  { path: 'home', component:HomeComponent },  // you must add your component here
  { path: '**', component:PageNotFoundComponent }
];

Example 2: how to navigate from one page to another in angular

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

export class YourComponentClassName implements OnInit {

    constructor(private router: Router) {}

    gotoHome(){
        this.router.navigate(['/home']);  // define your component where you want to go
    }

}

Example 3: how to navigate from one page to another in angular

<button class="btn btn-primary" (click)="gotoHome()">Home</button>

Tags:

Misc Example