@angular/router#UrlTree TypeScript Examples
The following examples show how to use
@angular/router#UrlTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: login.guard.ts From ReCapProject-Frontend with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.authService.isAuthenticated().pipe(
map((response) => {
return response.success;
}),
catchError(() => {
this.authService.logout();
this.router.navigate(['/login']);
this.toastrService.info('You must log in.');
return of(false);
})
);
}
Example #2
Source File: login.guard.ts From WiLearning with GNU Affero General Public License v3.0 | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const url = state.url || '/';
if ( this.auth.isLoggedIn ) {
this.logger.debug('user has been loggedIn, return true');
return true;
}
this.auth.redirectUrl = decodeURIComponent(url);
this.route.navigate(['/login']);
return false;
}
Example #3
Source File: auth.guard.ts From WiLearning with GNU Affero General Public License v3.0 | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if ( this.auth.isLoggedIn ) {
return true;
}
this.route.navigate(['/sigin']);
}
Example #4
Source File: not-authentication.guard.ts From nodejs-angular-typescript-boilerplate with Apache License 2.0 | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
if (!this.authenticationService.isAuthenticated) {
return of(true);
}
this.router.navigate(['/']).then();
return of(true);
}
Example #5
Source File: authentication.guard.ts From nodejs-angular-typescript-boilerplate with Apache License 2.0 | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
if (this.authenticationService.isAuthenticated) {
return of(true);
}
this.router.navigate(['/auth/login']).then();
return of(true);
}
Example #6
Source File: auth.guard.ts From bulwark with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
return this.checkLogin();
}
Example #7
Source File: admin.guard.ts From bulwark with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
return this.checkLogin();
}
Example #8
Source File: auth-guard.service.ts From blog2020 with MIT License | 6 votes |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (!this.chatService.username) {
return this.router.createUrlTree(['sign-in']);
}
return true;
}
Example #9
Source File: not-friend.guard.ts From onchat-web with Apache License 2.0 | 6 votes |
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.friendService.isFriend(+next.params.userId).pipe(
map(({ data }: Result<number>) => {
// TODO 写完单聊之后,自己跟自己也是好友,把this.globalData.user.id == next.params.userId删除
const isFriend = !!data || this.globalData.user?.id === next.params.userId;
isFriend && this.navCtrl.back();
return !isFriend;
})
);
}
Example #10
Source File: auth.guard.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
async canActivate(
_route: ActivatedRouteSnapshot,
_state: RouterStateSnapshot
): Promise<boolean | UrlTree> {
const hasLoggedIn = await this.diaBackendAuthService.hasLoggedIn();
if (!hasLoggedIn) {
return this.router.parseUrl('/login');
}
return hasLoggedIn;
}
Example #11
Source File: judgAuth.guard.ts From ng-ant-admin with MIT License | 6 votes |
canActivateChild(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
this.userInfoService.getUserInfo().subscribe(res => this.authCodeArray = res.authCode);
// 如果有authCode,则表示是页面上点击按钮跳转到新的路由,而不是菜单中的路由
while (route.firstChild) {
route = route.firstChild;
}
if (!!route.data['authCode']) {
return this.getResult(route.data['authCode'], this.authCodeArray);
}
// 如果是菜单上的按钮,则走下面
this.getMenu(this.menuNavList, state.url);
// 没找到菜单,直接回登录页
if (!this.selMenu) {
return this.getResult(fnGetUUID(), this.authCodeArray);
}
const selMenuCode = this.selMenu.code;
this.selMenu = null;
// 找到了菜单,但是菜单的权限码用户不拥有,则跳转到登录页
return this.getResult(selMenuCode!, this.authCodeArray);
}
Example #12
Source File: judgAuth.guard.ts From ng-ant-admin with MIT License | 6 votes |
getResult(code: string, authCodeArray: string[]): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (authCodeArray.includes(code)) {
return true;
} else {
this.message.error('您没有权限登录该模块');
this.loginOutService.loginOut();
return this.router.parseUrl('/login');
}
}
Example #13
Source File: auth.guard.ts From fyle-mobile-app with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.authService.getEou().then((eou) => {
if (!eou) {
this.router.navigate(['/', 'auth', 'sign_in']);
}
return !!eou;
});
}
Example #14
Source File: admin.guard.ts From ReCapProject-Frontend with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> | Promise<boolean | UrlTree> | boolean | UrlTree {
let userMail: string | null = this.localStorageService.get<string>(
'userMail'
);
return this.authService.isAuthenticated(userMail, ['admin']).pipe(
map((response) => {
return response.success;
}),
catchError(() => {
this.router.navigate(['']);
this.toastrService.info('You are not authorized to access this page.');
return of(false);
})
);
}
Example #15
Source File: jobrequest.guard.ts From Developing-Multi-platform-Apps-with-Visual-Studio-Code with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let url = next.url[0].path;
if (this.authorizationService.isUserLoggedIn()) {
if (url == "jobrequest" && this.authorizationService.user.role == "user")
return true;
else
this.router.navigate(['/login']);
}
else {
this.router.navigate(['/login']);
}
}
Example #16
Source File: employee.guard.ts From Angular-Cookbook with MIT License | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
return this.auth.loggedInUserType === UserType.Employee;
}
Example #17
Source File: auth.guard.ts From Angular-Cookbook with MIT License | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
const loggedIn = !!this.auth.isLoggedIn();
if (!loggedIn) {
this.router.navigate(['/auth']);
return false;
}
return true;
}
Example #18
Source File: agent.guard.ts From Developing-Multi-platform-Apps-with-Visual-Studio-Code with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
debugger;
let url = next.url[0].path;
if (this.authorizationService.isUserLoggedIn()) {
if (url == "agent" && this.authorizationService.user.role == "agent")
return true;
else
this.router.navigate(['/login']);
}
else {
this.router.navigate(['/login']);
}
}
Example #19
Source File: admin.guard.ts From Angular-Cookbook with MIT License | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
):
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree>
| boolean
| UrlTree {
return this.auth.loggedInUserType === UserType.Admin;
}
Example #20
Source File: is-there-wallets.guard.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
guardLogic(): Observable<boolean | UrlTree> {
return this.walletsQuery.isThereWallet$
.pipe(switchMap(status => {
if (!!status) {
return of(true);
}
return this.router.navigate(['/create-account'])
.then(_ => false);
}));
}
Example #21
Source File: auth.guard.ts From Angular-Cookbook with MIT License | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const loggedIn = !!this.auth.isLoggedIn();
if (!loggedIn) {
this.router.navigate(['/auth']);
return false;
}
return true;
}
Example #22
Source File: can-access-connect.guard.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return selectPersistStateInit()
.pipe(switchMap(() => {
return forkJoin([
this.walletsQuery.selectAll().pipe(take(1)),
this.walletsAccountsQuery.selectAll().pipe(take(1))
])
.pipe(map(values => {
const canAccess = values.every(value => value.length > 0);
if (!canAccess) {
this.router.navigate(['/connect/no-wallet'], {
queryParams: route.queryParams,
});
return false;
} else {
return true;
}
}));
}));
}
Example #23
Source File: auth-guard-service.guard.ts From ng-devui-admin with MIT License | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (!this.authService.isUserLoggedIn()) {
this.i18nValues = this.translate.instant('authNotice');
this.toastService.open({
value: [
{
severity: 'info',
summary: this.i18nValues['summary'],
content: this.i18nValues['content'],
},
],
life: 2000,
});
this.router.navigate(['login']);
return false;
} else {
return true;
}
}
Example #24
Source File: communityfolder.guard.ts From msfs-community-downloader with GNU Affero General Public License v3.0 | 6 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const communityFolder = this.settingsService.getSettings().communityPath;
if (!communityFolder || communityFolder === '') {
this.router.navigateByUrl('/settings');
}
return true;
}
Example #25
Source File: auth.guard.ts From Angular-Cookbook with MIT License | 6 votes |
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const loggedIn = !!this.auth.isLoggedIn();
if (!loggedIn) {
this.router.navigate(['/auth']);
return false;
}
return true;
}
Example #26
Source File: ios-view-restriction.guard.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 5 votes |
canActivateChild(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.guardLogic();
}
Example #27
Source File: is-there-wallets.guard.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 5 votes |
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.guardLogic();
}
Example #28
Source File: authentication.guard.ts From nodejs-angular-typescript-boilerplate with Apache License 2.0 | 5 votes |
canActivateChild(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): boolean | UrlTree {
return true;
}
Example #29
Source File: is-there-wallets.guard.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 5 votes |
canActivateChild(
childRoute: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.guardLogic();
}