In my project, there is an Isotope Component that I want to keep protected from unauthorized access. If a user is not logged in and tries to navigate directly to the Isotope page by entering a specific route like:
http://localhost:4200/register
and then proceeds to enter:
http://localhost:4200/isotopes, the Isotope page should not be displayed but instead briefly flashes the HTML template of the component before redirecting to the login page. I want to make sure that no content is visible during these redirections. Here's a snippet of code related to the Isotope component: I am unsure about which part of the code might be causing this issue.
export class IsotopesComponent implements OnInit {
theisotopes: IsotopesComponent[];
selectedIsotope: IsotopesComponent;
constructor( private isotopesService: IsotopesService,
private authService: AuthService,
private routetheuser: Router) { }
ngOnInit() {
this.getIsotopes();
}
getIsotopes() { this.isotopesService.getIsotopes()
.then((isotopes ) => {
this.theisotopes = isotopes;
//console.log(this.theisotopes)
})
.catch((err) => {
this.routetheuser.navigate(['/login']);
});
}// getIsotopes
}// class