I am using ui.router & ngResource with AngularJS, & my question is :
How do I RENDER 404 without redirecting to it e.g A user typed http://www.example.com/wrong-page-name , he should just be shown the 404 page, and the URL shouldn't change.
Currently this is how I did it but it redirects
angular.module('app')
.run(['$rootScope', '$state', function($rootScope, $state) {
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
if(error.status === 404) {
$state.go('innerPages.page', {slug:"not-found"});
}
});
})
.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider.state('innerPages.page', {
url: ':slug',
views : {
'content@':{
templateUrl : '...',
controller : 'pageController'
},
'pageHeader@' : {
templateUrl : "...",
controller : 'pageController'
}
},
resolve:{
page: ['pageService', '$stateParams', function (pageService, $stateParams) {
return pageService.get({slug:$stateParams.slug}).$promise;
}]
}
});
}]);
Thanks for Help !