0

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.

1 Answer 1

1

Found answer at lasts

app.get('/*', function(req, res, next) {
  res.sendFile(__dirname + '/app_client/index.html');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.