I am using webpack-dev-server at the dev side for my react-redux app and for production, I am bundling all JS files into one bundle.js . Now I created a basic express app and serving the bundle.js and index.html using the following code.
server.js
app.use(express.static('app'));
app.get('*', (req, res) => {
res.sendFile(__dirname + "/app/" + "index.html");
});
The following is my React component for routes:
return (
<div>
<Router>
<div>
<Header/>
<Route exact path="/" component={Home}/>
<Route path="/login" component={Login}/>
<Route path="/signup" component={Signup}/>
<Route path="/forgetPassword" component={ForgetPassword}/>
<Route path="/wallets" component={Wallets}/>
<Route path="/orders" component={Orders}/>
<Route path="/settings" component={Settings}/>
<Route path="/markets" component={MarketsList}/>
<Route path="/market/:marketPair" component={MarketDetail}/>
<Route path="/resetPassword/:token" component={ResetPassword}/>
</div>
</Router>
</div>
);
The problem is for the nested routes. The single-level routes like login and signup work fine. But the routes like /market/:marketPair and /resetPassword/:token give the following error at the browser console:
bundle.js:1 Uncaught SyntaxError: Unexpected token <
When clicked bundle.js , it shows my index.html file.
Can anyone help?