实际上,在通过react-
router和heroku文档进行搜索的3个小时之前,我首先遇到了这篇文章。对于swyx,以及其他有相同问题的人,我将概述实现此功能所需要做的最少工作。
router.js- (显然将AppSplash和AppDemo更改为您的组件)
export default <Router history={hashHistory}> <Route path="/" component={App}> <IndexRoute component={AppSplash}/> <Route path="demo" component={AppDemo}/> </Route></Router>app.js
import React, { Component } from 'react'class App extends Component {static propTypes = { children: PropTypes.node}render() { const { children } = this.props return ( <div> {children} </div> )}}export default App在主目录的根目录中创建一个新文件,并将其命名为 static.json 。把它放进去。
{ "root": "build/", "clean_urls": false, "routes": { "/**": "index.html" }}再次推送到heroku。路线这次应该起作用。
说明:
您需要修改Heroku的默认Webpack,否则服务会与如何处理客户端路由相混淆。本质上是static.json的作用。其余的只是根据“ react-router”文档处理路由的正确方法。



