canactivate

Angular: Run canActivate on each route change

笑着哭i 提交于 2021-02-18 06:09:06
问题 I got stuck recently with Angular route guards. CanActive runs only once when the page is loaded and does not run on route change within the guarded route. I think this was changed because it used to run on each change. From what I read in forums, I should use CanActivateChild. The thing is, our application consists of several modules, that have several route descendants and when I use CanActivateChild in root module, it is called several times when changing the route. I find it dumb to

Angular: Run canActivate on each route change

送分小仙女□ 提交于 2021-02-18 06:06:11
问题 I got stuck recently with Angular route guards. CanActive runs only once when the page is loaded and does not run on route change within the guarded route. I think this was changed because it used to run on each change. From what I read in forums, I should use CanActivateChild. The thing is, our application consists of several modules, that have several route descendants and when I use CanActivateChild in root module, it is called several times when changing the route. I find it dumb to

Route Guard: How can I set true or false based on params set from HttpPost?

只谈情不闲聊 提交于 2020-01-16 12:02:47
问题 My code: @Injectable() export class UserRouteAccessService implements CanActivate { authorized = [ 'AGREEMENTS_VIEW', 'PROSPECTS_VIEW', 'AGREEMENTS_INSERT_UPDATE', 'PRODUCTS_INSERT_UPDATE', 'PROSPECTS_INSERT_UPDATE', 'DOCUMENTS_VIEW', 'DOCUMENTS_INSERT_UPDATE', ]; constructor(private router: Router, private securityService: CralSecurityService) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { //boolean var this

Route Guard: How can I set true or false based on params set from HttpPost?

纵饮孤独 提交于 2020-01-16 12:02:06
问题 My code: @Injectable() export class UserRouteAccessService implements CanActivate { authorized = [ 'AGREEMENTS_VIEW', 'PROSPECTS_VIEW', 'AGREEMENTS_INSERT_UPDATE', 'PRODUCTS_INSERT_UPDATE', 'PROSPECTS_INSERT_UPDATE', 'DOCUMENTS_VIEW', 'DOCUMENTS_INSERT_UPDATE', ]; constructor(private router: Router, private securityService: CralSecurityService) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { //boolean var this

implementing canActivate auth guard in angular

北慕城南 提交于 2019-12-01 14:34:14
I have a service with this function that returns true or false on rather or not a token is valid loggedIn() { return this.http.get('http://localhost:3000/users/validateToken') .map(res => res.json()).map(data => data.success); } I have a auth guard with can activate on protected routes that uses this. canActivate(){ this.authService.loggedIn().subscribe(res => { if(res) { return true; } else { this.router.navigate(['/login']) return false; } }) } But i get this error. incorrectly implements interface 'CanActivate'. Types of property 'canActivate' are incompatible. Type '() => void' is not

How to execute in first a function and in second canActivate()

一笑奈何 提交于 2019-11-29 15:28:13
I have this AuthGuard. In this code I want to create a condition. If my resetpasss is not null I want to navigate in here ResetPassIdComponent else I want to navigate in LoginFirstComponent. For this I create AuthGuard. export class AuthGuard implements CanActivate { myappurl: any; resetpasss: any; constructor(private router: Router, private auth: LoginService) { } geturl() { handleOpenURL((appURL: AppURL) => { console.log('Got the following appURL1', appURL); this.myappurl = appURL let url_1 = this.myappurl.toString(); let url_id = url_1.split("/").reverse()[0]; this.resetpasss = url_id let

How to execute in first a function and in second canActivate()

末鹿安然 提交于 2019-11-28 09:29:23
问题 I have this AuthGuard. In this code I want to create a condition. If my resetpasss is not null I want to navigate in here ResetPassIdComponent else I want to navigate in LoginFirstComponent. For this I create AuthGuard. export class AuthGuard implements CanActivate { myappurl: any; resetpasss: any; constructor(private router: Router, private auth: LoginService) { } geturl() { handleOpenURL((appURL: AppURL) => { console.log('Got the following appURL1', appURL); this.myappurl = appURL let url_1