I'm trying to serve a react app (that use router) using express. The react app supposedly is accessible through /dashboard
.
Everything is working well on the /dashboard
route that supposed to show the login page. But if I try to access different routes, example /dashboard/foo
It shows nothing.
It turns out when the HTML page request the .js
file, the server return with the index.html
file instead of the .js
file.
I'm using this code in the index.js
file:
app.use(
['/dashboard', '/dashboard/*'],
express.static(path.join(__dirname, 'dashboard')),
);
have also tried this code:
app.use(
'/dashboard',
express.static(path.join(__dirname, 'dashboard')),
);
app.get(
'/dashboard/*',
(req, res) => {
res.sendFile(__dirname + "/dashboard/index.html"));
}
);