Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions apps/angular/60-async-redirect/src/app/dashboard.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -13,7 +12,7 @@ import { UserProfileService } from './user-profile.service';
</button>
<button
class="rounded border border-black bg-white px-4 py-2 text-black hover:bg-gray-200"
(click)="navigate()">
routerLink="/account">
User Page
</button>
</div>
Expand All @@ -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 {}
7 changes: 7 additions & 0 deletions apps/angular/60-async-redirect/src/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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 = [
{
Expand All @@ -12,6 +14,11 @@ export const routes: Routes = [
children: [
{ path: '', pathMatch: 'full', component: Dashboard },
{ path: 'profile', component: ProfilePage },
{
path: 'account',
pathMatch: 'full',
redirectTo: () => inject(UserProfileService).getProfile(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

},
{ path: 'admin', component: AdminPage },
{ path: 'user', component: UserPage },
],
Expand Down