how to navigate from one page to another in angular

56

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
    }

}

how to navigate from one page to another in angular -

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

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 }
];

Comments

Submit
0 Comments