简体   繁体   中英

Controlling access to view in angularJs

I want to limit access to view by button only. I mean I want to let user access the view only when he clicked the button (can't access if he just pasted url to view in address bar). And not by ng-show with would just not show the view but by blocking it from loading.

Possible scenarios:

  1. user is in users list view -> user is clicking 'Add user button' -> 'Add user' view is loading - that's OK, that's how it should work
  2. user is pasting address to 'Add user' view in address bar and trying to enter it - this try should be blocked, any other try besides by clicking button should be blocked.

Is there a way to do it? I'm using ui-router btw.

If you're using ui-router, you can use the state without url. So, when user clicks the button 'Add user button' - you can just change the state, but not the url. In this case, nobody can access 'Add user' view by url.

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.

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