【发布时间】:2018-02-13 20:01:59
【问题描述】:
我正在尝试将 create-react-app 部署到具有自定义域的 GitHub 页面上的相对路径。例如。 www.example.com/myproject
我正在使用react-router-dom、react-router-redux 和 react-router-bootstrap
我已在packages.json 中将主页设置为http://www.example.com/myproject(也尝试过homepage = "."),并为我的历史配置了基本名称:
...
export const history = createHistory({ basename: '/myproject' });
const middleware = [thunk, routerMiddleware(history)];
...
const composedEnhancers = compose(applyMiddleware(...middleware), ...enhancers);
const store = createStore(rootReducer, initialState, composedEnhancers);
部署的应用程序在www.mydomain.com/myproject 上运行,我可以通过应用程序链接进行导航。
但是当我尝试直接输入路径(例如www.example.com/myproject/account)或在子页面上刷新浏览器时,我得到了 404。
长期目标是为 dev 和 prod 环境配置不同的相对路径,如 this answer 中所述,但首先我只需要使其在部署中工作。
【问题讨论】:
-
你需要一个服务器端脚本来为你处理路由,例如用相同的 index.html 响应所有端点
标签: react-router create-react-app react-router-redux