Open In App

How to force redirect to a particular route in angular?

Introduction:

We can use the property binding concept and we can pass query parameters to routerLink. Using Property binding we can bind queryParams property and can provide the required details in object.



Property Binding: It is a concept where we use square bracket notation to bind data to Document Object Model(DOM) properties of Hypertext markup language(HTML) element.




import {Component, OnInit} from '@angular/core'
   
@Component({
   
selector:'app-property',
template:
`<p [textContent]="title"></p> 
`
})
   
export class AppComponent implements OnInit{
   
constructor(){}
ngOnInit() {}
   
title='Property Binding example in GeeksforGeeks';
   
}

Output:



We can implement the route re-direction in two ways:
1) The first method is by doing from .html file.
2) The second method is from the .ts file.

Syntax for .html file:
 




<a [routerLink]="[/path]" >
   State Details 
</a>


Article Tags :