Having an issue with direct links to pages containing a parameter. While links from the page itself work, accessing the page directly or refreshing it causes it to break and not load anything. This problem is occurring within a blog application I am developing.
For example, localhost/blog loads correctly, but when navigating to localhost/blog/name-of-article directly, it fails to load. The Chrome Javascript console displays the error "Uncaught SyntaxError: Unexpected token < " for all javascript files. There is also a problem when the URL has a trailing "/" which could be related to Angular issues.
Here is a snippet of relevant code from my routes:
app.config(['$routeProvider','$locationProvider',
function($routeProvider,$locationProvider){
$routeProvider.
when('/',{
templateUrl: '/partials/home.html',
controller: 'HomeController as HomeCtrl'
}).
when('/home',{
templateUrl: '/partials/home.html',
controller: 'HomeController as HomeCtrl'
}).
when('/blog',{
templateUrl: '/partials/blog.html',
controller: 'BlogController as blogCtrl'
}).
when('/blog/:name', {
templateUrl: '/partials/article.html',
controller: 'ArticleController as articleCtrl'
}).
otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
}]);
The server-side is built using Node/Express, serving an API for the Angular app.
app.use('*', function(req, res){
res.sendFile(__dirname + '/public/index.html');
console.log('page loaded');
});
Additional routes are set up for /api/contact and /api/article.