Is there a way to have an optional attribute at the beginning of the url in ui-router? If so, how?
I want to achieve sth like this:
.state(\'events\'
I see no reason why you wan't do it in a standard ui-router
state setup.
DEMO
JAVASCRIPT
angular.module('app', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('state1', {
url: ':city/events/:id',
templateUrl: 'partials/events.html',
controller: 'EventsController'
})
.state('state2', {
url: ':abc/cities/:x/:y',
templateUrl: 'partials/cities.html',
controller: 'CitiesController'
});
})
.controller('EventsController', function($scope, $stateParams) {
angular.extend($scope, $stateParams);
})
.controller('CitiesController', function($scope, $stateParams) {
angular.extend($scope, $stateParams);
});