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
- Fixes https://github.com/angular-ui/ui-router/issues/2327 — committed to piotrd/ui-router by deleted user 8 years ago
- Fixes https://github.com/angular-ui/ui-router/issues/2327, kudos to @pocesar — committed to piotrd/ui-router by deleted user 8 years ago
- Merge pull request #2478 from piotrd/fixes/2327 fix(common.js): "Cannot read property 'params' of undefined" errors Closes #2327 — committed to angular-ui/ui-router by christopherthielen 8 years ago
- Fixes https://github.com/angular-ui/ui-router/issues/2327, kudos to @pocesar — committed to ExpFront/ui-router by deleted user 8 years ago
@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:
Now I have this
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.