javascript - Using HTML5 with Angularjs and Node/Express and the MEAN.js boilerplate -
i'm using mean.js (http://meanjs.org/generator.html) boilerplate starting point app, love inbuilt authentication/authorization.
however, i'm having problem using html5.
in angular app i've set html5(true)
, know need set catchall route other requests redirected.
i have following routes on express root , catchall:
///this app/controllers/core.server.controller:
exports.index = function(req, res) { res.render('index', { user: req.user || null, request: req }); }; exports.catchall = function(req, res){ res.redirect('/'); };
and routing itself
'use strict'; module.exports = function(app) { // root routing var core = require('../../app/controllers/core.server.controller'); app.route('/').get(core.index); app.route('*').get(core.catchall); };
now pages redirecting no problem when enter routes garbage, when enter route exists in express (with no associated view i'm getting server output).
here route mean express:
'use strict'; /** * module dependencies. */ var users = require('../../app/controllers/users.server.controller'), articles = require('../../app/controllers/articles.server.controller'); module.exports = function(app) { // article routes app.route('/articles') .get(articles.list) .post(users.requireslogin, articles.create); // finish binding article middleware app.param('articleid', articles.articlebyid); };
i have no view associated in express/node - in angular.
so when navigate localhost:3000/articles via link angular manages route , renders correct angular template.
however, when enter localhost:3000/articles , press enter (or refresh browser on url) following:
[{"_id":"5555ede9dac9d0d99efae164","user":{"_id":"5554fa21141c5aef7b0354d7","displayname":"heny as"},"__v":0,"content":"this blurb him","title":"vp, global marketing","created":"2015-05-15t13:00:25.177z"}]
but want getting rendered page template angular
can help?
this because call server url (wich same used ajax calls), need
either intercept request type in server side (ajax | not ajax) , redirect no ajax root path (/) , angular use ajax articles in client side.
define single root (/) serving single web application , use (/api/...) handle ajax requests.
Comments
Post a Comment