1
2 content_copy
3
4 <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
5 link to user component
6</a>
7
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}
1<a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
2 link to user component
3</a>
1First you need to make component using 'ng generate'
2$ ng generate component home
3$ ng generate component about
4
5Next, in the src/app/app-routing.module.ts file import the components as follows:
6
7import { NgModule } from '@angular/core';
8import { Routes, RouterModule } from '@angular/router';
9
10import { HomeComponent } from './home/home.component';
11import { AboutComponent } from './about/about.component';
12Next, add the routes as follows:
13
14const routes: Routes = [
15 { path: 'home', component: HomeComponent },
16 { path: 'about', component: AboutComponent }
17
18];
19So now if you visit the /home path you should go to home component and if you visit the /about path you should go to the about component.
20/*
21I hope it will help you.
22Namaste
23Stay Home Stay Safe
24*/
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*/
1<router-outlet></router-outlet>
2<router-outlet name='left'></router-outlet>
3<router-outlet name='right'></router-outlet>