1
我正在编写一个Web应用程序,它使用react
作为客户端,express
作为服务器端。
我正在使用react-router
(link)路由客户端页面。
使用hashHistory
它很简单,工作正常,但现在我想使用browserHistory
。使用服务器路由反应路由器浏览器历史记录
正如在react-router
教程中提到的,我需要告诉我的服务器预计客户端请求,所以当我们渲染客户端页面时,它将服务于index.html
。
我无法找到处理来自客户端的页面请求和服务器处理请求的方法。
例如,我在路径/product
中有一个页面,但我也有一个服务器处理端点/authenticate
。
在react-router
教程它说,使用以下命令:
// server.js
// ...
// add path.join here
app.use(express.static(path.join(__dirname, 'public')))
// ...
app.get('*', function (req, res) {
// and drop 'public' in the middle of here
res.sendFile(path.join(__dirname, 'public', 'index.html'))
})
但这样会导致每一个请求(包括/authenticate
)将其送回index.html
。我怎样才能合并这两个?