W
W
What1slov32020-02-14 22:07:05
JavaScript
What1slov3, 2020-02-14 22:07:05

There is a SPA on React.js and Node.js, how to implement a page change?

There is a SPA on React.js and Node.js, when the button is pressed, a fetch request is sent to the server, a response arrives and you need to do a redirect along with it, but then Cannot GET / is displayed, because the files go through app.use(express.static ...), and the URL on that page is already different, but how can I write it so that a get request for any URL still issues index.html? I'm new to backend so sorry if this is a stupid question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
casoer, 2020-02-14
@casoer

app.get('*', function(req, res){
  res.sendfile(__dirname + '/public/index.html');
});

These three lines are at the very end. And don't forget to change the path to index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question