ui-router: Random "Cannot read property 'params' of undefined" errors

My client side analytics is getting filled with the same errors that seems to be related to ui-router

TypeError Cannot read property 'params' of undefined (inheritParams > js:2245)  

TypeError Cannot read property 'params' of undefined <a analytics="click" analytics-category="'login'" analytics-label="'criar'" ui-sref="login.index.criar"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <a class="header-menu-item" ui-sref-active="selected" analytics="click" analytics-category="'login'" analytics-label="'criar'" ui-sref="login.index.criar"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <a class="header-menu-item" ui-sref-active="selected" analytics="click" analytics-category="'login'" analytics-label="'entrar'" ui-sref="login.index.login"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <a ng-repeat="item in menu track by $index" ui-sref-active="selected" ng-attr-ui-sref="{{ :: item.sref }}" class="square header-menu-item header-main-item" ng-bind=" :: item.name"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <a ui-sref-active="selected" ng-attr-ui-sref="{{ :: item.sref }}" ng-bind=" :: item.name"> (inheritParams > js:2245)   

TypeError Cannot read property 'params' of undefined <a ui-sref="user.coupons.ativos" ui-sref-active="selected" analytics="click" analytics-category="'mobile-logged-dropdown'" analytics-label="'coupons'"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <a ui-sref="user.profile" ui-sref-active="selected" analytics="click" analytics-category="'mobile-logged-dropdown'" analytics-label="'profile'"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <button class="btn nav-fixed-btn btn-primary btn-smaller" analytics="click" analytics-category="'login'" analytics-label="'entrar'" ui-sref="login.index.login"> (inheritParams > js:2245)

TypeError Cannot read property 'params' of undefined <img ui-sref="index" src="/content/clients/wsf/logo.svg"> (inheritParams > js:2245)
            $stateProvider.state('login', {
                url: '/login',
                abstract: true,
                template: '<div ui-view></div>'
            });

            $stateProvider.state('login.index', {
                url: '/',
                abstract: true,
                templateUrl: '/templates/boxes/login',
                controller: Controllers.Login,
                controllerAs: 'login'
            });

            $stateProvider.state('login.index.login', {
                url: '',
                views: {
                    'inner': {
                        templateUrl: '/templates/boxes/cadastrado'
                    }
                }
            });

            $stateProvider.state('login.index.criar', {
                url: 'criar',
                views: {
                    'inner': {
                        templateUrl: '/templates/boxes/criar'
                    }
                }
            });

            $stateProvider.state('user', {
                abstract: true,
                url: '/user',
                template: '<div ui-view></div>',
                data: {
                    allowed: true
                }
            });

            $stateProvider.state('user.profile', {
                url: '/profile',
                templateUrl: '/templates/partials/user/index'
            });

            $stateProvider.state('user.coupons', {
                url: '/coupons', 
                templateUrl: '/templates/partials/user/coupons'
            });

            $stateProvider.state('user.coupons.ativos', {
                url: '/ativos',
                views: {
                    'tables': {
                        templateUrl: '/templates/partials/user/ativos'
                    }
                }
            });

I can’t reproduce this on local machine, so I’m a little stumped

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@pocesar I found what was triggering the issue in my case. Hope it can help others.

Turns out in my case it was being triggered by a workaround I had to wrote because Prototype.js was messing with Array.prototype.toJSON. Since I can’t drop Prototype because my code runs on arbitrary websites as a widget I solved the issue (on our website) narrowing the workaround by checking if the “bad” version of Prototype is present.

Previously I had this:

var _json_stringify = JSON.stringify;
JSON.stringify = function(value) {
  var _array_tojson = Array.prototype.toJSON;
  delete Array.prototype.toJSON;
  var r=_json_stringify(value);
  Array.prototype.toJSON = _array_tojson;
  return r;
};

Now I have this

if ('object' === typeof window.Prototype) {
    var PrototypeVersion = window.Prototype.Version.split('.');
    if (parseInt(PrototypeVersion[0], 10) > 1) return;
    if (parseInt(PrototypeVersion[1], 10) > 6) return;
    if (parseInt(PrototypeVersion[2], 10) > 1) return;
    var _json_stringify = JSON.stringify;
    JSON.stringify = function(value) {
       var _array_tojson = Array.prototype.toJSON;
       delete Array.prototype.toJSON;
       var r=_json_stringify(value);
       Array.prototype.toJSON = _array_tojson;
       return r;
    };
}

By doing this our app does not suffer from this issue anymore (we don’t use Prototype). But anyone using ui.router and messing with Array.prototype will probably suffer from it until the PR that solves it for good gets merged.