I currently have a status URL defined as:
... /: table / edit /: identifier
-> Therefore, both URLs:
... / products / edit / 5 and ... / notValidTable / edit / 5
load my tableEdit state as defined below:
tableEdit.state.js:
angular.module(โmyApp')
.config(function($stateProvider) {
$stateProvider
.state('tableEdit', {
url: '/:table/edit/:id',
templateUrl: โ../table_edit/table_edit.html',
controller: 'TableEditCtrl'
});
});
Q - As I know, my parameter: table in tableEdit should be only one of: "products", "suppliers", "customers", "keywords" or "that", how can I limit my values โโaccepted for my state For loading?
Here is the solution that I have, but I hope for feedback or a better way to solve this problem:
app.js:
angular.module(โmyApp', [
'ui.router',
])
.config(
['$urlRouterProvider',
function($urlRouterProvider) {
$urlRouterProvider
.when('/:table/edit/:id', ['$match', '$state',
function($match, $state) {
if ($match.table !== 'products'
&& $match.table !== 'providers'
&& $match.table !== 'customer'
&& $match.table !== 'keywords'
&& $match.table !== 'topics') {
$state.transitionTo('tablesHome');
} else {
$state.transitionTo('tableEdit', $match, true); }
}
}
])
.otherwise('/home');
])
tableEdit ': table', ?
.