Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.config(function($routeProvider) {
- $routeProvider
- .when('/', {
- controller: 'MainCtrl',
- template: 'Allowed from anywhere.<br>Go to main <a href="#/main">page</a>',
- restricted: false
- })
- .when('/main', {
- controller: 'MainCtrl',
- template: 'Allowed from anywhere.<br>Go to restricted <a href="#/restr">page</a>',
- restricted: false
- }).when('/restr', {
- controller: 'RestrictedPageCtrl',
- template: 'Allowed only from main',
- restricted: '/main'
- });
- });
- app.run(function($rootScope, $location, $route) {
- $rootScope.$on('$locationChangeStart', function(event, next, current) {
- var next = $route.routes[$location.path()];
- var currentPath = current.split('#')[1];
- if (next.restricted && next.restricted !== currentPath) {
- $location.path('/');
- alert('You are trying to reach a restricted page!!!!');
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement