You could implement OnInit
interface and add redirection/check in ngOnInit
method and add @CanActivate
to your child components:
class Static{
static authenticated:boolean = false;
static initialized:boolean = false;
}
@CanActivate(()=>{
if(Static.authenticated && Static.initialized){
return true;
}
return false;
})
protected ngOnInit():any
{
this.loginFacade.refresh().subscribe(event=>
{
var url = event.success ? this.location.path() : Routes.LOGIN;
Static.authenticated = event.success;
this.router.recognize(url).then(()=>
{
return Promise.resolve(url);
}, (e)=>
{
return Promise.resolve(Routes.LOGIN);
}).then((url)=>
{
Static.initialized = true;
return this.router.navigateByUrl(url);
});
});
}
also remove default route.