I'm working on a Node app using Express as well as Angular. I'm using Angular for routing and have my routes setup like so:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: '/partials/main'
//controller: 'IndexController'
}).when('/discover', {
templateUrl: '/partials/discover'
}).when('/user/home', { //HERES THE PROBLEM CHILD!!!!!
templateUrl: '/partials/user/home'
}).otherwise({
redirectTo: '/'
});
}]).config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
}]);
Now, whenever I try and call /user/home
-- The page goes into an infinite loop and keeps reloading the controller. I can see in the node console that the page was called from partials/user/home
which definitely contains a Jade file. I've checked other posts, most of them are solved with ass the /
in the beginning of the partials path, that didn't help here. The page loads fine if I transfer home.jade
into the /partials
directory with no sub directory. Any ideas?
Update: It seems the infinite loop happens anytime I try to load a partial in any sub-directory of partials.
Per request:
Node -- App.js:
app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
app.get('*', routes.index);
And routes/index.js
exports.index = function(req, res) {
res.render('index', { title: 'Open Innovation Station' });
}
exports.partials = function(req, res) {
res.render('partials/' + req.params.name);
}
Using html5Mode(true)
, you will have to concern yourself with any relative paths -- which you are using for your partials. The recursion in your case, I believe, could have been resolved by adding:
<base href="/"></base>
to your <head>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With