I started using typed parameters (such as {id:int}
) in my route configuration. If a state doesn't match because of the type, otherwise
does not appear to trigger.
For example:
$stateProvider
.state('stuff', {
url: '/version/{version:int}/stuff',
templateUrl: // ...,
controller: // ...
})
.state('list', {
url: '/list',
// ...
});
$urlRouterProvider.otherwise('/list');
If the version is "x" (not an int), I am not redirected to the list page. Instead I end up on an empty page with no errors in the console.
How can I fix this?
(Clarification: I'm typing in invalid URLs in the address bar to test this, not using ui-sref
.)
Update: I believe I've found what's causing it (thanks to @RadimKöhler for an example that eliminated some possibilities). See my plunk.
Everything works fine except for URLs that fail to match a custom type built with $urlMatcherFactoryProvider.type()
. I used a guid
type based on the answers to this question.
I can work around this by using regular expressions in the URL, but it would be nice to have a fix.
More info: Adding pattern
to the custom Type object appears to fix this. The pattern has to leave out the anchors (^$
), so something like:
pattern: /[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}/i
I'd say, that the concept as you wanted, is working. There is a working example
this state def (1:1 to question)
will properly handle these links:
these will not work (as expected) - so they will not created any href (such state with such params does not exist)
these
href
will be redirect to otherwiseCheck it in action here