Questions tagged canactivate

Explore the latest questions and answers asked by our top developers.

angular 9 why canActivateChild start befor canActivate completed?

in my program I have a func in canActivateChild that need to occur after canActivate finished , but the child component loads befor canActivate of the parent finish,why? my routing-module: const routes: Routes = [ { path: ”, component: MainComponent, canActivate: [LoadDataGuard, ConfigureJsGuard], canActivateChild: [EnterChildGuard], canDeactivate: [CleanupJsGuard], data: { modelService: ModelService, } , children: [ […]

Angular9 canActivateChild starts before canActivate finished

I have routing-module file with these routes: const routes: Routes = [ { path: ”, component: MainComponent, canActivate: [LoadDataGuard, ConfigureJsGuard], canActivateChild: [EnterChildGuard], canDeactivate: [CleanupJsGuard], data: { modelService: ModelService, } , children: [ { component: ChildComponent, ……. In LoadDataGuard I write a canActivate function which calls to enterTab function (enterTab manage the data of childComponent , […]

By Dvora
Published
Categorized as angular, canactivate, canactivatechild, promise Tagged , , ,

Angular – how to improve local development experience?

Currently I’m building Angular 12 based project. ​ It has custom CanActivate guard, which communicates with some services using 3rd party library. ​That library also requires https to pass all authentication flow. I’ve started from this: Updated hosts file and added custom host there like: 127.0.0.1 customhost.local.test.com Updated angular.json => serve section with host and […]

Angular RouteGuard "A function whose declared type is neither ‘void’ nor ‘any’ must return a value"

I have a route guard that checks if a user has access to a resource, before proceeding. After the subscription, I check if the user has access, and if not, redirect using parseUrl or return true. @Injectable({ providedIn: ‘root’ }) export class PortfolioGuard implements CanActivate { constructor(private resourceAccessService: ResourceAccessService, private router: Router) { } canActivate(route: […]

How to return a value after `retryWhen` expires? (for `canActivate` guard)

When I reload my page, it always goes to blank page instead of the same page. The reason behind this is canActivate method which is cheking for user’s permission gets invoked as soon as user refreshes the page and it is not able to get user data immediately. User data comes after some seconds. I […]

Delay canActivate call when page refreshes in order to wait for the data to load

When I reload my page, it always goes to blank page instead of the same page. The reason behind this is canActivate method which is cheking for user’s permission gets invoked as soon as user refreshes the page and it is not able to get user data immediately. User data comes after some seconds. Is […]

By Radiant
Published
Categorized as angular, angular-ui-router, canactivate, rxjs Tagged , , ,

How to reactivate deleted item

I am working on a web app and I need to implement reactivation of deleted items. I have a method that checks if the item exists already: getExistence( item: string ): Observable<any> { if (item) { return this.http.get<any>( this.existenceUrl + item ); } } and its interface looks like this export interface ItemExistence { short: […]

By user16814898
Published
Categorized as angular, canactivate, service, typescript Tagged , , ,

How can i use canActivate() to block access to certain routes?

I am actually working on an website that have multiple users. I want to update a user’s information and it works so fine but when i type on the URL an id of another user instead of the current user i can simply access to that profile while i am not supposed to . Source: […]

By BHIRI Yosri
Published
Categorized as angular, auth-guard, canactivate, routes Tagged , , ,

How to fix error TS2416: Property ‘canActivate’ in type ‘KeycloakAuthGuard’ is not assignable to the same property in base type ‘CanActivate’?

I am very new to the angular project. After I clone the project and try to up the project with ng serve. So I am getting an error like. ERROR in node_modules/keycloak-angular/lib/core/services/keycloak-auth-guard.d.ts(10,5): error TS2416: Property ‘canActivate’ in type ‘KeycloakAuthGuard’ is not assignable to the same property in base type ‘CanActivate’. Type ‘(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) […]

By Dasun
Published
Categorized as angular, angular6, canactivate, keycloak Tagged , , ,

CanActivate on pagination in Angular

I have server side pagination on a list screen in angular. When I click on the link to visit the screen, sometimes the pagination number doesn’t appear and I have to double click the link to get the number. I have used CanActivate guard on the screens so that the screen gets displayed only when […]

By Ahmad
Published
Categorized as angular, auth-guard, canactivate Tagged , ,
1 2 3 4

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq