1const routes: Routes = [
2 { path: '', redirectTo: '/first-component', pathMatch: 'full' }, // redirect to `first-component`
3 { path: 'first-component', component: FirstComponent },
4 { path: 'second-component', component: SecondComponent },
5 { path: '**', component: PageNotFoundComponent }, // Wildcard route for a 404 page
6];
1import {Router} from '@angular/router'; // import router from angular router
2
3export class Component{ // Example component..
4 constructor(private route:Router){}
5
6 go(){
7 this.route.navigate(['/page']); // navigate to other page
8 }
9}
1import { NgModule } from '@angular/core';
2import { RouterModule, Routes } from '@angular/router';
3import { HeroesComponent } from './heroes/heroes.component';
4
5const routes: Routes = [
6 { path: 'heroes', component: HeroesComponent }
7];
8
9@NgModule({
10 imports: [RouterModule.forRoot(routes)],
11 exports: [RouterModule]
12})
13export class AppRoutingModule { }
14
1// Here’s a basic example using the navigate method:
2
3goPlaces() {
4 this.router.navigate(['/', 'page-name']);
5}
6
7/*
8I hope it will help you.
9Namaste
10*/