Reputation: 121
I'm trying to use html5 mode in Angular JS app for sake of SEO. However, I faced the problem for Express serving index.html to request. The deep linking didn't work and cannot refresh page.
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");
});
I already try many researches from many sources, approach such as
app.get('/', function(req, res) {
res.sendFile('index.html');
});
or
router.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'app_client', 'index.html'));
});
or
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
None seems to work. I know that something must be wrong in my code, but i don't know where.
Upvotes: 0
Views: 71
Reputation: 121
Found answer at lasts
app.get('/*', function(req, res, next) {
res.sendFile(__dirname + '/app_client/index.html');
}
Upvotes: 1