mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 05:13:02 -05:00
Additions/55 back button navigation (#1016)
feat: new angular back button navigation challenge
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<router-outlet></router-outlet>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterLink, RouterOutlet } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [RouterOutlet, RouterLink],
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
})
|
||||
export class AppComponent {}
|
||||
10
apps/angular/55-back-button-navigation/src/app/app.config.ts
Normal file
10
apps/angular/55-back-button-navigation/src/app/app.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { APP_ROUTES } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(APP_ROUTES),
|
||||
],
|
||||
};
|
||||
24
apps/angular/55-back-button-navigation/src/app/app.routes.ts
Normal file
24
apps/angular/55-back-button-navigation/src/app/app.routes.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { HomeComponent } from './home/home.component';
|
||||
import { SensitiveActionComponent } from './sensitive-action/sensitive-action.component';
|
||||
import { SimpleActionComponent } from './simple-action/simple-action.component';
|
||||
|
||||
export const APP_ROUTES: Routes = [
|
||||
{
|
||||
path: '',
|
||||
pathMatch: 'full',
|
||||
redirectTo: 'home',
|
||||
},
|
||||
{
|
||||
path: 'home',
|
||||
component: HomeComponent,
|
||||
},
|
||||
{
|
||||
path: 'simple-action',
|
||||
component: SimpleActionComponent,
|
||||
},
|
||||
{
|
||||
path: 'sensitive-action',
|
||||
component: SensitiveActionComponent,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<h2 mat-dialog-title>Delete file</h2>
|
||||
<mat-dialog-content>Would you like to delete cat.jpeg?</mat-dialog-content>
|
||||
<mat-dialog-actions>
|
||||
<button mat-button mat-dialog-close>No</button>
|
||||
<button mat-button mat-dialog-close cdkFocusInitial>Ok</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import {
|
||||
MatDialogActions,
|
||||
MatDialogClose,
|
||||
MatDialogContent,
|
||||
MatDialogRef,
|
||||
MatDialogTitle,
|
||||
} from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dialog-dialog',
|
||||
templateUrl: './dialog.component.html',
|
||||
standalone: true,
|
||||
imports: [
|
||||
MatButtonModule,
|
||||
MatDialogActions,
|
||||
MatDialogClose,
|
||||
MatDialogTitle,
|
||||
MatDialogContent,
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class DialogComponent {
|
||||
readonly dialogRef = inject(MatDialogRef<DialogComponent>);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<a mat-raised-button routerLink="/simple-action" routerLinkActive="active">
|
||||
Go to simple dialog action page
|
||||
</a>
|
||||
|
||||
<a mat-raised-button routerLink="/sensitive-action" routerLinkActive="active">
|
||||
Go to sensitive dialog action page
|
||||
</a>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { RouterLink } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [MatButtonModule, RouterLink],
|
||||
selector: 'app-home',
|
||||
templateUrl: './home.component.html',
|
||||
})
|
||||
export class HomeComponent {}
|
||||
@@ -0,0 +1,3 @@
|
||||
<button mat-raised-button (click)="openDialog()">
|
||||
Open dialog with confirmation dialog on browser back button click
|
||||
</button>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { DialogComponent } from '../dialog/dialog.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [MatButtonModule],
|
||||
selector: 'app-sensitive-action',
|
||||
templateUrl: './sensitive-action.component.html',
|
||||
})
|
||||
export class SensitiveActionComponent {
|
||||
readonly #dialog = inject(MatDialog);
|
||||
|
||||
openDialog(): void {
|
||||
this.#dialog.open(DialogComponent, {
|
||||
width: '250px',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<button mat-raised-button (click)="openDialog()">Open simple dialog</button>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { DialogComponent } from '../dialog/dialog.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [MatButtonModule],
|
||||
selector: 'app-simple-action',
|
||||
templateUrl: './simple-action.component.html',
|
||||
})
|
||||
export class SimpleActionComponent {
|
||||
readonly #dialog = inject(MatDialog);
|
||||
|
||||
openDialog(): void {
|
||||
this.#dialog.open(DialogComponent, {
|
||||
width: '250px',
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user