I'm working on a NodeJS project including some AngularJS for routing management and I can't find out how to solve my current problem : I'm trying to check if a chosen HTML file exists before routing it. I've tried lots of solutions but for the moment, nothing seems to work. Here is my code :
var app = angular.module("domhanWebSite", ["ngRoute"]);
app.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(false).hashPrefix('!');
//routing management
$routeProvider
.when("/", {
templateUrl : "pages/home.html"
})
.when("/404_not_found", {
templateUrl : "pages/404_not_found.html"
})
.when("/encyclopedie/personnages/:character_html", {
//here verification is missing
templateUrl : function (url_attr) {
return "pages/encyclopedia/characters/"+url_attr.character_html;
}
})
.otherwise( {
redirectTo: "/404_not_found"
});
});
For the third "when", I would like to check whether or not the HTML exists, and if it doesn't (because sometimes, the URL attribute does not correspond to anything), finally route to 404 error page. Does anyone have a brilliant solution ? =)