Redid 404 and 500 routing, and redid authguard to point to /login
This commit is contained in:
parent
20330bc220
commit
8939c18335
3 changed files with 18 additions and 20 deletions
|
@ -1,21 +1,21 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
|
|
||||||
constructor(private router: Router) { }
|
constructor(private router: Router) { }
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
if (localStorage.getItem('sessionKey')) {
|
if (localStorage.getItem('sessionKey')) {
|
||||||
console.log('session key found')
|
console.log('session key found')
|
||||||
// logged in so return true
|
// logged in so return true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not logged in so redirect to login page with the return url
|
// not logged in so redirect to login page with the return url
|
||||||
console.log('no session key found')
|
console.log('no session key found')
|
||||||
this.router.navigate(['/pages/login'], { queryParams: { returnUrl: state.url }});
|
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ import { AuthGuard } from './_guards/auth.guard';
|
||||||
import { FullLayoutComponent } from './layouts/full-layout.component';
|
import { FullLayoutComponent } from './layouts/full-layout.component';
|
||||||
import { SimpleLayoutComponent } from './layouts/simple-layout.component';
|
import { SimpleLayoutComponent } from './layouts/simple-layout.component';
|
||||||
|
|
||||||
|
// Error Pages
|
||||||
|
import { P404Component } from './pages/404.component';
|
||||||
|
import { P500Component } from './pages/500.component';
|
||||||
|
|
||||||
// Submodules
|
// Submodules
|
||||||
import { AuthModule } from './auth/auth.module';
|
import { AuthModule } from './auth/auth.module';
|
||||||
|
|
||||||
|
@ -42,6 +46,8 @@ import { AuthModule } from './auth/auth.module';
|
||||||
BreadcrumbsComponent,
|
BreadcrumbsComponent,
|
||||||
SIDEBAR_TOGGLE_DIRECTIVES,
|
SIDEBAR_TOGGLE_DIRECTIVES,
|
||||||
AsideToggleDirective,
|
AsideToggleDirective,
|
||||||
|
P404Component,
|
||||||
|
P500Component,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
AuthGuard,
|
AuthGuard,
|
||||||
|
|
|
@ -6,10 +6,13 @@ import { AuthGuard } from './_guards/auth.guard';
|
||||||
import { FullLayoutComponent } from './layouts/full-layout.component';
|
import { FullLayoutComponent } from './layouts/full-layout.component';
|
||||||
import { SimpleLayoutComponent } from './layouts/simple-layout.component';
|
import { SimpleLayoutComponent } from './layouts/simple-layout.component';
|
||||||
|
|
||||||
|
import { P404Component } from './pages/404.component';
|
||||||
|
import { P500Component } from './pages/500.component';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
redirectTo: 'dashboard',
|
redirectTo: '/dashboard',
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -38,19 +41,8 @@ export const routes: Routes = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{ path: '404', component: P404Component },
|
||||||
path: 'pages',
|
{ path: '500', component: P500Component },
|
||||||
component: SimpleLayoutComponent,
|
|
||||||
data: {
|
|
||||||
title: 'Pages'
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
loadChildren: './pages/pages.module#PagesModule',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
Reference in a new issue