Hi so I have declared my route with the id like this {path: 'spreadsheet/:id', component: ContactParent}
so here I can get the id
by using ActivatedRoute
but how I can get spreadsheet
, if I do this.router.url
it gives me spreadsheet/20
but I only need spreadsheet
Try this...
constructor( private route: ActivatedRoute ) {
console.log(route.pathFromRoot[1].snapshot.url[0].path);
}
If you go to, for example, http://localhost:4200/spreadsheet/3, the above code will log "spreadsheet"
import {Router} from '@angular/router'; // import Router from @angular/router
constructor(private router: Router){ // private member of Router
const currentPageUrl = router.url; // router.url contain the active route info
console.log('Activated router is ' + currentPageUrl);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With