Can I set a default value of a parameter of a route in AngularJS? Is there a way to have /products/123
and /products/
handled by the same route ?>
Not sure if this question is specific to $routeProvider
but in $stateProvider, you can achieve this by
myApp.config(function($stateProvider) {
$stateProvider
.state('products', {
url: '/:productId',
templateUrl: "/dashboard/products.html",
controller: 'ProductController',
params: {
productId: {
value: "defaultValue",
squash: true // or enable this instead to squash `productId` when empty
}
}
});
});