Here is the progress I have made with ui-router states:
$stateProvider
.state('tools', {
url: '/tools/:tool',
template: '<div ui-view=""></div>',
abstract: true,
onEnter: function ($stateParams, $state, TOOL_TYPES) {
if (TOOL_TYPES.indexOf($stateParams.tool) === -1) {
$state.go('error');
}
}
})
.state('tools.list', {
url: '',
templateUrl: 'app/tools/tools.tpl.html',
controller: 'ToolsController'
})
.state('tools.view', {
url: '/:id/view',
templateUrl: 'app/tools/partials/tool.tpl.html',
controller: 'ToolController'
});
The parent state requires parameter tool
, which must be included in the TOOL_TYPES
array. If not available, the user will be redirected to the error page.
Although everything functions correctly, I am encountering two errors:
TypeError: Cannot read property '@' of null
TypeError: Cannot read property '@tools' of null
It seems that the child states are being triggered regardless. Is there a way to prevent this or achieve my desired outcome differently?