I'm struggling to make this code function properly:
.....
.when('/channel/:id/:slug',{
templateUrl:'views/channel/index.html',
controller:'Channel',
publicAccess:true,
sessionAccess:true
})
.....
app.controller('Channel', ['$scope','$routeParams', function ($scope,$routeParams) {
}]);
app.run(function($rootScope, $location, $route) {
var routesOpenToSession = [];
angular.forEach($route.routes, function(route, path) {
console.log(path);
console.log(route);
route.sessionAccess && (routesOpenToSession.push(path));
});
$rootScope.$on('$routeChangeStart', function(event, nextLoc, currentLoc) {
var closedToSession = (-1 === routesOpenToSession.indexOf($location.path()));
if(closedToSession && $rootScope.session.id_user) {
$location.path('/');
}
});
});
Can anyone explain why I am unable to access the page using site.com/channel/9/my-slug
even when $rootScope.session.id_user
exists and sessionAccess:true
is set?
Whenever I try to access it, I get redirected to /
, while other static URLs work fine with sessionAccess:true
. For example channel/staticparam
works, but dynamic parameters cause issues.
Here is the result from the console log: