How get variable from url path variable in angular2(v12)
path: 'shop/:id', <-- get id from here
component: RedirectGuard,
canActivate: [RedirectGuard],
data: {
externalUrl: `https://example.com/shop/:id` <-- set id to here
}
How get variable from url path variable in angular2(v12)
path: 'shop/:id', <-- get id from here
component: RedirectGuard,
canActivate: [RedirectGuard],
data: {
externalUrl: `https://example.com/shop/:id` <-- set id to here
}
You want to use the ActivateRoute class in your component:
import { ActivatedRoute, Router } from '@angular/router';
export class RedirectGuard implements OnInit {
constructor(
private route: ActivatedRoute
) {}
ngOnInit() {
const id = this.route.snapshot.params.id;
this.router.navigate([`shop`, id]);
}
}