I don't want a user to enter a particular page if he is not required to. How can I stop a user from visiting the page if he manually type url in browser. What should I use , I am new to angularjs , idk if this is very silly question. Any help is appreciated.
Import router from @angular/router In your component constructor check if authentication fails then go to link which you want. below is a simplest example of this procedure.
//other imports
import {Router} from '@angular/router';
@Component({
//your components html, selector,providers, directives
})
export class MyComponent{
constructor(router:Router){
//set this signed in in local storage when your user signs in successfully
if(window.localStorage.getItem('signedIn')=="false")
{
//route wherever you want to
router.navigate(['']);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.