0

I want to check my URL that has exactly a specific format. I have this URL

www.example.com?rt=12365

I want to check if income URL has below format

?rt= number

then do something. I use the router like my below code:

const queryParams = router.url

but I don't know how to check it. I'm new to typescript and angular, please help me

heliya rb
  • 682
  • 8
  • 26

2 Answers2

3

Try this

 constructor(private route: ActivatedRoute) {

 }

 if (this.route.snapshot.queryParams['rt']) {
      if ( !isNaN(this.route.snapshot.queryParams['rt']) && angular.isNumber(this.route.snapshot.queryParams['rt'])) 
       {
         }
 }

Hope useful for you

A.khalifa
  • 2,366
  • 3
  • 27
  • 40
2

You can use queryParams

constructor(private route: ActivatedRoute) {

}
ngOnInit() {
    this.route.queryParams.subscribe(params => {
        console.log(params.rt);
        if(!isNaN(params.rt)){
            console.log("URL Match");
        }else{
            console.log("URL does not Match");
        }
    });
}
Krishna Rathore
  • 9,389
  • 5
  • 24
  • 48