I have this route
After much trial and error, I came up with:
$urlMatcherFactoryProvider.type('guid', {
encode: angular.identity,
decode: angular.identity,
equals: function(a, b) { return a.toUpperCase() === b.toUpperCase(); },
is: function(val) {
// Local to avoid any lastIndex issues
var GUID_REGEXP = /^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/i;
return GUID_REGEXP.test(val);
},
// No anchors or flags with pattern
pattern: /[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}/
});
This is based on @just-boris's answer. One key difference is pattern
. Without this it appears that invalid GUIDs will not trigger $urlRouterProvider.otherwise()
.