【发布时间】:2017-03-27 00:05:01
【问题描述】:
为了 SEO,我正在尝试在 Angular JS 应用程序中使用 html5 模式。但是,我遇到了 Express 服务 index.html 请求的问题。深层链接无效,无法刷新页面。
App.js
app.use(serveStatic(path.join(__dirname, 'public')));
app.use(serveStatic(path.join(__dirname, 'node_modules')));
app.use(serveStatic(path.join(__dirname, 'app_client')));
app.use('/api', routesApi);
app.all('/*', function(req, res, next) {
res.sendFile('./app_client/index.html', { root: __dirname });
console.log("send index");
});
我已经尝试了许多来源的研究,例如
app.get('/', function(req, res) {
res.sendFile('index.html');
});
或
router.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'app_client', 'index.html'));
});
或
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
似乎没有一个工作。我知道我的代码一定有问题,但我不知道在哪里。
【问题讨论】: