As told by Can angularjs routes have optional parameter values?
and AngularJS: Routing with URL having optional parameters
question mark ?
with parameter name should make it optional. Its not helping me.
var app = angular.module('app', ['ui.router','ngRoute']);
app.config(function ($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/a');
$stateProvider.state('a', {
url: '/a',
templateUrl: 'views/a.html'
}).state('b', {
url: '/b/:code?/:d?',
templateUrl : 'views/b.html'
})
});
This url http://localhost:xx/kk/#/b/1/2 works fine for me. But http://localhost:xx/kk/#/b (without any parameter) and http://localhost:xx/kk/#/b/1 not working for me...
You could see I am using $stateProvider
with ui-router. I do not want to switch to $urlRouteProvider