Register a custom type that outputs and discards data. Docs here: http://angular-ui.imtqy.com/ui-router/site/#/api/ui.router.util . $ UrlMatcherFactory
Define a custom type. Implement encoding, decode, there is a template:
var productType = { encode: function(str) { return str && str.replace(/ /g, "-"); }, decode: function(str) { return str && str.replace(/-/g, " "); }, is: angular.isString, pattern: /[^/]+/ };
Now register your custom type as βproductβ with $urlMatcherFactoryProvider :
app.config(function($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvider) { $urlMatcherFactoryProvider.type('product', productType); }
Now define your url parameter as a product, and the custom type will do the mapping for you:
$stateProvider.state('baseproductdetail', { url: '/detail/{productName:product}-:productId/', controller: function($scope, $stateParams) { $scope.product = $stateParams.productName; $scope.productId = $stateParams.productId; }, template: "<h3>name: {{product}}</h3><h3>name: {{productId}}</h3>" });
Work panel: http://plnkr.co/edit/wsiu7cx5rfZLawzyjHtf?p=preview
Chris t
source share