W
W
WebLedNik2021-02-03 22:43:01
Node.js
WebLedNik, 2021-02-03 22:43:01

How to use express routing with connect-history-api-fallback?

Connected connect-history-api-fallback, but after that routing does not work.
For example I call:

app.get("/about", function(request, response){
response.send("<h1>О сайте</h1>");
});

But it gives 404. What should I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebLedNik, 2021-02-03
@WebLedNik

Found the answer.

app.use(history({
  rewrites: [
    {
      from: /^\/about\/*$/,
      to: function (context) {
        return context.parsedUrl.path
      }
    }
  ]
}))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question