Skip to content

Commit cbf235f

Browse files
committed
Migrate to functional guards in routing module
1 parent 863c966 commit cbf235f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

scilog/src/app/app-routing.module.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgModule } from '@angular/core';
2-
import { RouterModule, Routes } from '@angular/router';
2+
import { mapToCanDeactivate, RouterModule, Routes } from '@angular/router';
33

44
import { DashboardComponent } from './logbook/dashboard/dashboard.component';
55
import { TodosComponent } from './logbook/widgets/todos/todos.component';
@@ -25,13 +25,13 @@ const routes: Routes = [
2525
{ path: 'download/:fileId', component: DownloadComponent },
2626
{ path: 'logbooks/:logbookId', component: LogbookComponent,
2727
children: [
28-
{ path: 'dashboard', component: DashboardComponent, canDeactivate: [NavigationGuardService] },
28+
{ path: 'dashboard', component: DashboardComponent, canDeactivate: mapToCanDeactivate([NavigationGuardService]) },
2929
{ path: 'todos', component: TodosComponent },
3030
{ path: 'logbook', component: LogbookItemComponent },
3131
{ path: 'snippetViewer', component: SnippetViewerComponent },
3232
{ path: 'chat', component: ChatComponent },
3333
{ path: 'graph', component: ChartComponent },
34-
{ path: 'dashboard-item', component: DashboardItemComponent, canDeactivate: [NavigationGuardService] },
34+
{ path: 'dashboard-item', component: DashboardItemComponent, canDeactivate: mapToCanDeactivate([NavigationGuardService]) },
3535
{ path: '**', redirectTo: '/overview', pathMatch: 'full' },
3636
]},
3737
{ path: 'viewSettings', component: ViewSettingsComponent, outlet: 'settings' },
@@ -42,6 +42,7 @@ const routes: Routes = [
4242

4343
@NgModule({
4444
imports: [RouterModule.forRoot(routes, { canceledNavigationResolution: 'computed' })],
45+
providers: [NavigationGuardService],
4546
exports: [RouterModule]
4647
})
4748
export class AppRoutingModule { }

scilog/src/app/app.module.ts

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ const appConfigInitializerFn = (appConfig: AppConfigService) => {
189189
],
190190
providers: [
191191
AppConfigService,
192-
NavigationGuardService,
193192
{
194193
provide: APP_INITIALIZER,
195194
useFactory: appConfigInitializerFn,

0 commit comments

Comments
 (0)