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

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

本文关键字:一页 重定向 angularjs 访问 网站 url 如果      更新时间:2023-09-26

如果不需要用户输入特定页面,我不希望用户输入。如果用户在浏览器中手动键入url,我如何阻止他访问该页面。我应该用什么,我是angularjs的新手,如果这是一个非常愚蠢的问题。感谢您的帮助。

从@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(['']);
        }
    }
  }