首页 > 开发 > NodeJS > 正文

react-router 使用browserHistory,应该如何配置后端

2017-09-08 17:11:17  来源:网友分享

react-router使用中,如果使用browserHistory替代hashHistory,应该如何对后端进行配置

解决方案

如使用express进行服务端配置:

const express = require('express')const path = require('path')const port = process.env.PORT || 8080const app = express()// serve static assets normallyapp.use(express.static(__dirname + '/public'))// handle every other route with index.html, which will contain// a script tag to your application's JavaScript file(s).app.get('*', function (request, response){  response.sendFile(path.resolve(__dirname, 'public', 'index.html'))})app.listen(port)console.log("server started on port " + port)