问题刷新页面nodejs cannot /get error

Problem refresh pages nodejs cannot /get error

我建立了一个网站,当我在主页上刷新时它很好,但是当我导航到其他页面时它也很好但是当我在这些其他页面上刷新时

Cannot GET /otherpage

我正在使用 react-navigation,如果我将它超链接,我认为它也可能无法正常工作。


require('rootpath')();
const express = require('express');
const app = express();
///
///
app.use('/accounts', require('./accounts/accounts.controller'));

if(process.env.NODE_ENV === 'production'){
 
  app.use(express.static('build'));

 

  }
server.js
build

文件目录

我该如何解决这个问题?

// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));

// An api endpoint that returns a short list of items
app.get('/api/getList', (req,res) => {
    var list = ["item1", "item2", "item3"];
    res.json(list);
    console.log('Sent list of items');
});

// Handles any requests that don't match the ones above
app.get('*', (req,res) =>{
    res.sendFile(path.join(__dirname+'/client/build/index.html'));
});

按照本教程进一步解释:https://dev.to/nburgess/creating-a-react-app-with-react-router-and-an-express-backend-33l3