Absolutely, it is completely feasible to access the URL displayed in the address bar. There are two methods to accomplish this: utilizing the ActivatedRoute
and using the Router
.
ActivatedRoute
The ActivatedRoute
necessitates an entry in the app-routing.module.ts
defining the components you wish to exhibit:
{ path: ':customerId/:state', component: YourComponent }
In your component file :
constructor(private route: ActivatedRoute) {
this.route.paramMap.subscribe(params => {
this.customerId = params.get('customerId');
this.state = params.get('state');
});
}
You can then construct your output based on the customerId
and state
parameters.
Router
If you opt not to utilize routing (or if you face restrictions), you can alternatively use the Router
to access the URL. Simply parse it as follows:
constructor(private router: Router) {
this.href = this.router.url;
}