I have a route path configured as:
{
path: 'user/:id/edit/:type',
component: UserEditTypeComponent,
},
I want to reach the path from the interceptor which i could access from activated routes as:
constructor(private activatedRoute: ActivatedRoute) {
}
ngOnInit() {
console.log(this.activatedRoute.routeConfig.path);
}
This results in returning this path user/:id/edit/:type
in the console.
I want to get the same path from interceptor which i have tried as:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let ar = this.injector.get(ActivatedRoute);
console.log(ar.routeConfig.path);
}
this returns error as: Cannot read property 'path' of null
. I have removed the path and tested and found routeConfig
to be null.
How do we get the activated route inside the interceptor?
Is there any other method to access the path
in interceptor?
If the question seems to be unclear could updated it with more information.