From 45d48b9bf6fd26a76bb3122d7124e3b8922548a8 Mon Sep 17 00:00:00 2001 From: jpaberzs Date: Thu, 3 Sep 2026 13:55:47 +0300 Subject: [PATCH] feat: added redirectTo --- .../60-async-redirect/src/app/dashboard.ts | 18 ++++-------------- .../60-async-redirect/src/app/routes.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/apps/angular/60-async-redirect/src/app/dashboard.ts b/apps/angular/60-async-redirect/src/app/dashboard.ts index 377c5e81d..b2955ead3 100644 --- a/apps/angular/60-async-redirect/src/app/dashboard.ts +++ b/apps/angular/60-async-redirect/src/app/dashboard.ts @@ -1,6 +1,5 @@ -import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; -import { Router, RouterLink, RouterOutlet } from '@angular/router'; -import { UserProfileService } from './user-profile.service'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { RouterLink, RouterOutlet } from '@angular/router'; @Component({ selector: 'app-dashboard', @@ -13,7 +12,7 @@ import { UserProfileService } from './user-profile.service'; @@ -22,13 +21,4 @@ import { UserProfileService } from './user-profile.service'; changeDetection: ChangeDetectionStrategy.OnPush, imports: [RouterOutlet, RouterLink], }) -export class Dashboard { - private router = inject(Router); - private userProfile = inject(UserProfileService); - - navigate() { - this.userProfile.getProfile().subscribe((profile) => { - void this.router.navigate(['/', profile]); - }); - } -} +export class Dashboard {} diff --git a/apps/angular/60-async-redirect/src/app/routes.ts b/apps/angular/60-async-redirect/src/app/routes.ts index 4a0f11835..774f59e54 100644 --- a/apps/angular/60-async-redirect/src/app/routes.ts +++ b/apps/angular/60-async-redirect/src/app/routes.ts @@ -1,16 +1,30 @@ +import { inject } from '@angular/core'; import { Routes } from '@angular/router'; import { AdminPage } from './admin-page'; import { App } from './app'; import { Dashboard } from './dashboard'; import { ProfilePage } from './profile-page'; import { UserPage } from './user-page'; +import { UserProfileService } from './user-profile.service'; export const routes: Routes = [ { path: '', component: App, children: [ - { path: '', pathMatch: 'full', component: Dashboard }, + { + path: '', + pathMatch: 'full', + component: Dashboard, + }, + { + path: 'getProfile', + redirectTo: () => { + const userProfile: UserProfileService = inject(UserProfileService); + + return userProfile.getProfile(); + }, + }, { path: 'profile', component: ProfilePage }, { path: 'admin', component: AdminPage }, { path: 'user', component: UserPage },