I sent you the documentation already. On Sun, Jul 3, 2016, 09:58 Simon Azzopardi <[email protected]> wrote:
> HI Lucas, > > thank you for your reply. > > Do you have an example how I can use the location object to get the > current url? > > Thank you > > > On Saturday, July 2, 2016 at 8:36:58 PM UTC+2, Lucas Lacroix wrote: > >> Use the location object: http://www.w3schools.com/jsref/obj_location.asp >> Then, when you redirect to the login, pass the current URL as an encoded >> parameter to the login URL. >> >> On Sat, Jul 2, 2016 at 9:41 AM, Simon Azzopardi < >> [email protected]> wrote: >> > 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. >>> >> >> >> >> -- >> Lucas Lacroix >> Computer Scientist >> System Technology Division, MEDITECH <http://ehr.meditech.com> >> 781-774-2293 >> > -- > 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. > -- 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.
