I have the following states configuration (simplified):
$stateProvider
.state(
'showitem',
{ url: '/item/{id}', templateUrl: 'showitem.html', controller: 'MyCtrl' }
)
.state(
'notFound',
{ url: '^*path', templateUrl: '404.html'}
);
When I enter /badurl
, 404 error is shown as expected.
When I enter /item/123
, the application's API is being queried for item with specified identifier. It returns item data on success or 404 HTTP header if the item could not be found. In order to detect such errors globally, I wrote a http interceptor:
$httpProvider.interceptors.push(function($q, $location) {
return {
responseError: function(rejection) {
if(rejection.status == 404)
$location.path('/404');
return $q.reject(rejection);
}
};
});
Code works but when the item's id is wrong, the /item/123
URL changes to /404
which shows an error page.
Question is - how to load the 404.html
view into my <div ui-view></div>
element without changing the URL?
There is a similar question but the templateProvider does not seem to address my problem.