Where do you do the redirect to the login component here though (when
canActivate() fails)?  It's obviously a nicer AOP style, but I've never
seen where people are doing the login redirect with this method.

On Tue, Jan 5, 2016 at 4:18 AM, Günter Zöchbauer <[email protected]> wrote:

> I think canActivate and Activate router lifecycle methods are the official
> way
> https://github.com/angular/router/issues/100
>
> On Tuesday, January 5, 2016 at 12:20:12 AM UTC+1, Mark Rathwell wrote:
>>
>> Looks like I missed the obvious on this one.  You can just subscribe to
>> route transitions and do the authentication checks and redirections there.
>> Subscribing in the top-level component constructor works as expected for me:
>>
>> this.router.subscribe((nextValue) => {
>>
>>     if (nextValue !== 'login' && nextValue !== 'register' &&
>> !this.sessionService.accessToken()) {
>>
>>         this.sessionService.data['urlRedirectAfterLogin'] = nextValue;
>>
>>         this.router.navigate(['/Login']);
>>
>>     }
>>
>> });
>>
>> On Mon, Jan 4, 2016 at 12:10 AM, Mark Rathwell <[email protected]>
>> wrote:
>>
>>> I'm interested in this also.  I have spent most of the day trying to
>>> make something work by overriding the router-outlet, but have only come up
>>> with dirty hacks that sort of work.
>>>
>>> There is literally zero information out there on authentication with
>>> Angular 2 that is still current and valid.  It is such a standard and
>>> critical thing, I must be missing something.
>>>
>>> On Tue, Dec 29, 2015 at 5:17 AM, Martin Wawrusch <[email protected]>
>>> wrote:
>>>
>>>> Hi guys, I am trying to set up routing with authentication properly.
>>>>
>>>> So far I am using the router's canActivate decorator to determine if
>>>> that component can be shown or not. The question is: where do I put the
>>>> redirect to a login page? Doing a hard redirect with window.location within
>>>> the canActivate check seems to be wrong). Should I override the
>>>> router-outlet instead, and if so, how?
>>>>
>>>>
>>>> --
>>>> 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.
>

-- 
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