簡體   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