【发布时间】:2018-02-19 08:06:32
【问题描述】:
我在节点中有简单的快速服务器:
const express = require('express')
const path = require('path')
const application = express()
const port = process.env.PORT || 80
const PUBLIC_DIR = 'public'
application.use(express.static(path.join(__dirname, PUBLIC_DIR)))
application.listen(port)
//handle 404
application.use((req, res) => {
res.send('404: Page not Found', 404)
});
//handle 500
application.use((error, req, res, next) => {
res.send('500: Internal Server Error', 500)
});
console.log(['HTTP server running on ', process.env.HOST, ' / ', port].join(''))
当我将“已构建”的反应应用程序放入公共文件夹时,服务器返回 index.html 好。但问题在于反应路由器。
我有这样的路由器:
/
/home
/about
当我转到 url localhost/ 时 - 工作正常,返回带有完整应用程序的 index html,但问题是当我转到 /home、/about 时,服务器返回 404,如何解决?如何重定向到反应路线?希望你能理解我。
感谢您的帮助
【问题讨论】: