Node.js 使用节点处理带有嵌套主干目录的PushState重定向
我对如何处理主干哈希和pushState有点困惑 基本上我想要Node.js 使用节点处理带有嵌套主干目录的PushState重定向,node.js,.htaccess,backbone.js,express,Node.js,.htaccess,Backbone.js,Express,我对如何处理主干哈希和pushState有点困惑 基本上我想要 localhost:3004/#/explore 将来 及 将来 第一件事是指定我的所有静态目录,这似乎是可行的,因为我可以通过浏览器直接访问所有文件 app.configure(function(){ app.use("/js", express.static( path.join(__dirname, 'www/js'))); app.use("/assets", express.static( path.
localhost:3004/#/explore
将来
及
将来
第一件事是指定我的所有静态目录,这似乎是可行的,因为我可以通过浏览器直接访问所有文件
app.configure(function(){
app.use("/js", express.static( path.join(__dirname, 'www/js')));
app.use("/assets", express.static( path.join(__dirname, 'www/assets')));
app.use("/style", express.static( path.join(__dirname, 'www/style')));
app.use("/templates", express.static( path.join(__dirname, 'www/templates')));
app.use("/config", express.static( path.join(__dirname, 'www/config')));
app.use(express.favicon());
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({
secret: 'adasdasdasdasdasdasdasdasdasdasd'
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());
app.use(allowCrossDomain);
app.use(app.router);
app.use(express.static(clientDir));
});
这似乎可行,因为我现在可以从位置栏导航到任何文件
我还可以使用pushState
Backbone.history.start({pushState: true});
我感到困惑的是捕获最初的页面调用并确保它命中index.html。不过,它还需要传入目录,以便主干路由器知道去哪里
几次失败的尝试包括:
app.get("*", function(req, res) {
fs.createReadStream(path.join(clientDir, 'index.html')).pipe(res);
});
另一个
app.get("*", function(req, res) {
res.redirect('http://localhost:3004#/'+req.url);
});
app.get('/', function(req, res){
res.sendfile(path.join(clientDir, 'index.html'));
});
另一个
app.get("*", function(req, res) {
res.redirect('http://localhost:3004#/'+req.url);
});
app.get('/', function(req, res){
res.sendfile(path.join(clientDir, 'index.html'));
});
任何想法都会有帮助
我对其他方法持开放态度,如htaccess等,但不确定这将如何与heroku部署配合使用。看起来这对我来说是可行的
app.get('/*', function(req, res){
res.sendfile(path.join(clientDir, 'index.html'));
});
app.get('/*', function(req, res){
res.sendfile(path.join(clientDir, 'index.html'));
});