I'd like to do something like this in my application, where the same level of the URL hits the either the baz
state, that absolutely named, or the biz
state that takes a parameter.
angular.module('foo')
.config(function($stateProvider){
$stateProvider
.state('baz', {
url: '/baz',
templateUrl: '/templates/baz.html'
})
.state('biz', {
url: '/:biz',
templateUrl: '/templates/biz.html',
resolve: {
biz: function($stateParams){
// resolve whatever $stateParams.biz should be
}
}
})
})
However, what's happening is ui-router is always hitting the biz
state, and interpreting "baz" as a parameter for that state. Is there an elegant way to let ui-router know that anything that hits "/baz" should resolve to the baz
state?
I know I can use $stateChangeStart
and do something like this:
$rootScope.$on('$stateChangeStart', function(event, toState, toParams){
if (toParams.biz === "baz"){
event.preventDefault();
$state.go('baz')
}
})
But this is far from elegant and seems like a hack.
I created a plunker here, which in fact shows, that the above state snippet is WORKING. Why, because these states are defined in the correct order:
The way how we can make it broken, is to switch the state def:
Check the broken link here
Summary: