I'm currently using ui-router to manage my routes in my angularjs app, and I was wondering if there was a way to modify the url that gets created.
Its better explained with an example. I have the following state
$stateProvider.state('items', { url: 'items/{itemName}', ... }); Then in my view I can transition to this state with
<a ui-sref="items({itemName:'Full Item Name'})">...</a> which, when clicked, to set the url to /items/Full%20Item%20Name What I would like to do is modify the url that will be generated to /items/full-item-name, but still have Full Item Name show up in the $stateParams.
I have managed to change the navigated url to what I wanted using
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { for (var prop in toParams) { var original = toParams[prop]; var pretty = makePretty(original); toParams[prop] = pretty; } }); This will change the toParams to their 'prettified' form before the route change happens so that the url will be what I want
Here is a plunk: http://plnkr.co/edit/8AhkitxFjy7H6ZwTkeT4?p=preview
The main thing that I am missing right now is the url that is pointed to by the link is still items/Full%20Item%20Name.
Am I missing something? Is there an easier way to approach this?