mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-16 15:40:11 +01:00
fix(docs): guard before redirecting
This commit is contained in:
parent
75f27e2cfc
commit
154a9945dc
4 changed files with 14 additions and 6 deletions
|
|
@ -15,12 +15,16 @@ export class ThemeGuard implements CanActivate {
|
|||
): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.currentThemeService.currentTheme$.pipe(
|
||||
map(theme => {
|
||||
const currentThemeExpiration = JSON.parse(theme).expires_in;
|
||||
const currentDate = new Date().getTime();
|
||||
if (!theme || currentDate > currentThemeExpiration) {
|
||||
if (!theme || this.hasExpired(theme)) {
|
||||
this.router.navigate(['themes']);
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
private hasExpired(theme): boolean {
|
||||
const currentThemeExpiration = JSON.parse(theme).expires_in;
|
||||
const currentDate = new Date().getTime();
|
||||
return currentDate > currentThemeExpiration;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export class CurrentThemeService implements OnDestroy {
|
|||
}
|
||||
|
||||
getCurrentTheme(): string {
|
||||
return JSON.parse(localStorage.theme).themeName;
|
||||
return localStorage.theme ? JSON.parse(localStorage.theme).themeName : 'default';
|
||||
}
|
||||
|
||||
calculateExpiration(iat: number): number {
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ export const routes: Routes = [
|
|||
},
|
||||
],
|
||||
},
|
||||
{ path: '', redirectTo: 'themes', pathMatch: 'full' },
|
||||
{ path: '**', redirectTo: 'themes' },
|
||||
{ path: '', redirectTo: 'pages/dashboard', pathMatch: 'full' },
|
||||
{ path: '**', redirectTo: 'pages/dashboard' },
|
||||
];
|
||||
|
||||
const config: ExtraOptions = {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { AnalyticsService } from './@core/utils/analytics.service';
|
|||
import { AbService } from './@core/utils/ab.service';
|
||||
import { withLatestFrom, filter } from 'rxjs/operators';
|
||||
import { SeoService } from './@core/utils/seo.service';
|
||||
import {CurrentThemeService} from './@core/utils/theme.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-app',
|
||||
|
|
@ -24,6 +25,7 @@ export class AppComponent implements OnInit {
|
|||
private activatedRoute: ActivatedRoute,
|
||||
private abService: AbService,
|
||||
private themeService: NbThemeService,
|
||||
private currentThemeService: CurrentThemeService,
|
||||
private seoService: SeoService) {
|
||||
|
||||
this.themeService.onThemeChange()
|
||||
|
|
@ -35,6 +37,8 @@ export class AppComponent implements OnInit {
|
|||
.subscribe((params: any) => {
|
||||
if (params.theme && this.themes.includes(params.theme)) {
|
||||
this.themeService.changeTheme(params.theme);
|
||||
} else {
|
||||
this.themeService.changeTheme(this.currentThemeService.getCurrentTheme());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue