nav guard added

This commit is contained in:
Drew Ansbacher
2021-11-03 14:12:05 -06:00
committed by Aiden McClelland
parent c17d35c83e
commit ffd8f7b278
3 changed files with 34 additions and 1 deletions

View File

@@ -1,10 +1,12 @@
import { NgModule } from '@angular/core'
import { PreloadAllModules, RouterModule, Routes } from '@angular/router'
import { NavGuard } from './guards/nav-guard'
const routes: Routes = [
{
path: 'init',
loadChildren: () => import('./pages/init/init.module').then( m => m.InitPageModule),
canActivate: [NavGuard],
},
{
path: 'product-key',
@@ -13,22 +15,27 @@ const routes: Routes = [
{
path: 'home',
loadChildren: () => import('./pages/home/home.module').then( m => m.HomePageModule),
canActivate: [NavGuard],
},
{
path: 'recover',
loadChildren: () => import('./pages/recover/recover.module').then( m => m.RecoverPageModule),
canActivate: [NavGuard],
},
{
path: 'embassy',
loadChildren: () => import('./pages/embassy/embassy.module').then( m => m.EmbassyPageModule),
canActivate: [NavGuard],
},
{
path: 'loading',
loadChildren: () => import('./pages/loading/loading.module').then( m => m.LoadingPageModule),
canActivate: [NavGuard],
},
{
path: 'success',
loadChildren: () => import('./pages/success/success.module').then( m => m.SuccessPageModule),
canActivate: [NavGuard],
},
]

View File

@@ -0,0 +1,22 @@
import { Injectable } from '@angular/core'
import { CanActivate, Router } from '@angular/router'
import { HttpService } from '../services/api/http.service'
@Injectable({
providedIn: 'root',
})
export class NavGuard implements CanActivate {
constructor (
private readonly router: Router,
private readonly httpService: HttpService,
) { }
canActivate (): boolean {
if (this.httpService.productKey) {
return true
} else {
this.router.navigateByUrl('product-key')
return false
}
}
}

View File

@@ -18,4 +18,8 @@ import { SuccessPageRoutingModule } from './success-routing.module'
],
declarations: [SuccessPage],
})
export class SuccessPageModule { }
export class SuccessPageModule {
constructor () {
console.log('SuccessModule loaded.')
}
}