Any idea guys please?

On Friday, July 1, 2016 at 2:01:12 PM UTC+2, Simon Azzopardi wrote:
>
> Hi guys,
>
> hope you're fine.
>
> I have a dilemma how I can navigate users back to the previous url where 
> they was after they were redirected to the login page.
>
> Currently, I have this AuthGuard service:
>
> 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;
>  }
>  });  
>     }
> }
>
> Then, I assigned it accordingly to my dashboard routes:
>
>
> 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
> ]}
>     ]
>   },
> ];
>
>
> Now I would like to know how I can get the previous url ater they were 
> redirected to the login, to login first.
>
> Any ideas please?
>
> thank you in advance.
>
> Kind Regards
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to