简体   繁体   中英

Express Routes for ejected create-react-app

I want to serve another static page for the route "/about", now I have :

app.use(express.static(path.resolve(__dirname, '..', 'build')));

app.get('/', (req, res) => {
  res.sendFile(path.resolve(__dirname, '..', 'build', 'index.html'));
});
app.get('/about', function (req, res) {
    console.log("here")
  res.sendFile(path.resolve(__dirname, '..', 'build', 'about.html'));
});

and I also have a post request

app.post('/getfrontpage', (req, res) => {
    console.log("FIRST PAGE", req.body.params.page)
});

The post request works, I use axios to make a call, but the "/about" route doesn't work when I'm changing the url

Do you have any errors on the server side?

The example above works for me: https://runkit.com/dionnis/5ab936152f32d7001211d85f

Note: I changed app.post('/getfrontpage' to app.get('/getfrontpage'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM