当我通过Node Express提供Angular 5应用程序时,当我访问 domain.com 时,Express静态服务将index.html提供出来,但是当我访问 domain.com/something 时,它可以正常工作。请问有人能帮助我解决这个问题吗?
app.use(express.static(path.join(__dirname, 'dist'))); //This line serves index.html how to deny it
app.use("/api", routes);
app.get('*', function(req, res) { //The reason it needs to be * so that it works with angular routes or it wont work
//This is never called when i visit domain.com. but it does when i visit domain.com/somthing
console.log("i was serverd");
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
预先感谢您的帮助 :)
dist/index.html
而不是express.static
吗? - vibhor1997a