我昨天在stackoverflow上发布了一个问题(刷新时不包含css和javascript),询问为什么我刷新网页后css和javascript没有包含在我的网页上并发现它是由html5mode引起的,所以从昨天开始,我一直在寻找这个问题的解决方案,但我无法真正得到答案。
我的文件夹结构
应用程序.js
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path')
, mongoose = require('mongoose');
var app = module.exports=express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/public/views');
app.set('view engine', 'ejs');
app.use(express.cookieParser());
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
app.use(function(request, response)
{
console.log("catch all");
writeFile("/public/views/master.ejs", request, response);
});
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.use(function (req,res) {
res.status(404).render('error', {
url: req.originalUrl
});
});
app.get('/', routes.index);
app.get('/:name', routes.view);
app.get('*', routes.risk);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
index.js
exports.index = function(req, res){
res.render('master', { title: 'Hello World' });
};
exports.view = function (req, res) {
var name = req.params.name;
res.render(name);
};
exports.risk = function(req, res){
res.sendfile(__dirname + "/public/views/master.ejs");
};
对于exports.risk,我试图让expressJs 在渲染其他母版页之前先渲染母版页,但它不起作用。
角Js
var SymSal = angular.module('SymSal',[]).
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: 'main.ejs',
controller: 'IndexCtrl'
}).
when('/login',{
templateUrl: 'login.ejs',
controller: 'IndexCtrl'
}).
when('/register',{
templateUrl: 'register.ejs',
controller: 'IndexCtrl'
}).
when('/about',{
templateUrl: 'about.ejs',
controller: 'IndexCtrl'
}).
otherwise({
templateUrl: 'error.ejs'
});
$locationProvider.html5Mode(true);
}]);
SymSal.controller('IndexCtrl',function(){
})
感谢您的帮助,谢谢!