[英]How to redirect back to same page (the page he is already in) if someone manually try to visit different url of the site in angularjs
如果不需要,我不希望用户输入特定页面。 如果用户在浏览器中手动键入URL,如何阻止用户访问该页面。 如果这是一个非常愚蠢的问题,我应该使用什么,我是angularjs的新手,idk。 任何帮助表示赞赏。
从@ angular / router导入路由器在组件构造函数中检查身份验证是否失败,然后转到所需的链接。 下面是此过程的最简单示例。
//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(['']);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.