0

I have a very menu intense website I am developing. It is provided it's menu system between two json objects. The first being the overarching menu system to control navigation and the second to control the current page's menu item actions.

My question is how would someone write a route config to handle a path based on variable depth uri's?

This function validates an in order array of paths from a given menu system.

function actionDrill(namelist, level, currentNode) {
    var i,
        curr,
        result;
    if(level == namelist.length - 1 && namelist[level] === currentNode.name) {
        return true
    }
    else if(currentNode.hasownProperty('submenus')) {
        result = false;
        for(i = 0; i < currentNode.submenus.length; i++) {
            curr = currentNode.submenus[i];
            if(namelist[level+1] === curr.name)
            {
                result = actionDrill(namelist, level+1, curr)
            }
            if(result) {
                break;
            }
        }
        return result
    }
    return false    
} 

This is my config. How would i edit '/:action' to handle the depth of the uri not being 1?

.config(['$routeProvider', function($routeProvider) {
    $routeProvider
    .when('/home', {
        templateUrl: 'partials/home.html',
        controller: 'MenuCtrl'
    })
    .when('/:action', {
        templateUrl: 'partials/action.html',
        controller: 'ActionCtrl',
        resolve: {
            action: function($q, $route) {
                var deferred = $q.defer(),
                    action = $route.current.params.action;


                if(actionDrill(action, 0, menuitems)) {
                    deferred.resolve(action);
                } else {
                    deferred.reject('Invalid Action');
                }

                return deferred.promise;
            }
        }
    })
    .otherwise({
        redirectTo: '/home'
    })
}]);
Luke Smith
  • 781
  • 3
  • 7
  • 15

1 Answers1

0

I found the answer here: AngularJS dynamic routing

Basically adding a * after /:action enables dynamic routing.

Community
  • 1
  • 1
Luke Smith
  • 781
  • 3
  • 7
  • 15