繁体   English   中英

如果有人手动尝试访问angularjs中网站的不同网址,如何重定向回同一页面(他已经在的页面)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM