Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. app.config(function($routeProvider) {
  2. $routeProvider
  3. .when('/', {
  4. controller: 'MainCtrl',
  5. template: 'Allowed from anywhere.<br>Go to main <a href="#/main">page</a>',
  6. restricted: false
  7. })
  8. .when('/main', {
  9. controller: 'MainCtrl',
  10. template: 'Allowed from anywhere.<br>Go to restricted <a href="#/restr">page</a>',
  11. restricted: false
  12. }).when('/restr', {
  13. controller: 'RestrictedPageCtrl',
  14. template: 'Allowed only from main',
  15. restricted: '/main'
  16. });
  17. });
  18.  
  19. app.run(function($rootScope, $location, $route) {
  20. $rootScope.$on('$locationChangeStart', function(event, next, current) {
  21. var next = $route.routes[$location.path()];
  22. var currentPath = current.split('#')[1];
  23. if (next.restricted && next.restricted !== currentPath) {
  24. $location.path('/');
  25. alert('You are trying to reach a restricted page!!!!');
  26. }
  27. });
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement