auth0-blog / angular2-authentication-sample

This is a sample that shows how to add authentication to an Angular 2 (ng2) app
MIT License
966 stars 334 forks source link

Avoided Route still load #43

Open jackesdavid opened 8 years ago

jackesdavid commented 8 years ago

( sorry about my english)

i think the code need a little change. If you want to avoid a route you need to skip activation, so my propose is We dont need to do load a route if will be avoided, so do not activate yet

    activate(instruction:ComponentInstruction)
    {
        var url = this.parentRouter.lastNavigationAttempt;
        //check in your way if the route is valid...
       // is not valid
        if (instruction.urlPath != 'About')
        {
            this.parentRouter.navigate(['/About']);
        }
        //is Valid
        else
        {
            return super.activate(instruction);
        }
    }