2016-11-13 49 views
0

我试图在SEO Angular JS应用程序中使用html5模式。但是,我面临快速服务index.html请求的问题。深层链接无法正常工作,无法刷新页面。快速服务index.html从Angular html5模式不起作用

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') 
}); 

似乎没有工作。我知道我的代码中一定有错,但我不知道在哪里。

回答

1

找到答案在持续

app.get('/*', function(req, res, next) { 
    res.sendFile(__dirname + '/app_client/index.html'); 
}