import { Injectable } from '@angular/core';
import { CanActivate,
Router,
ActivatedRouteSnapshot,
RouterStateSnapshot } from '@angular/router';
import { AuthService } from './auth.service';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class AuthGuard {
constructor(private _authService: AuthService, private _router: Router) {}
canActivate(): Observable<boolean>{
return this._authService.checkIfUserIsLoggedIn()
.map((result) => {
if (result["_body"] == "true") {
return true;
} else {
this._router.navigate(['/login'], { queryParams: {message: 'You must be logged in to access Dashboard!'}});
return false;
}
});
}
}
export const DashboardRoutes: RouterConfig = [
{
path: '',
redirectTo: '/dashboard',
terminal:true
},
{
path: '/dashboard',
component: DashboardComponent,
canActivate: [AuthGuard],
children:[
{path: '', component: DashboardHomeComponent, canActivate: [AuthGuard]},
{path: '/jobs', component: JobsComponent, canActivate: [AuthGuard]}
]
},
];
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
I sent you the documentation already.
Open your browser debugging tools and play around with the location object. Between that and the documentation I already sent you, you should be able to figure it out.
Like I said already: you will need to adjust the URL to match your application.
Yes.