【发布时间】:2016-06-17 17:46:15
【问题描述】:
我正在尝试使用带有 react-router 的基本名称,如 on the react-router docs 所记录的那样。这是因为 base href 已被弃用。
这是我现在拥有的:
import { Route, Router, useRouterHistory } from 'react-router';
import { createHistory } from 'history';
import { render } from 'react-dom';
var history = useRouterHistory(createHistory)({
basename: '/subdirectory'
});
render(
<Router history={history}>
<Route path='/' component={App}>
<Route path='next' component={Next} />
</Route>
</Router>,
document.getElementById('root')
);
当我转到http://the-url.com/subdirectory 时,页面按预期加载(呈现App 组件)。但是,当转到 http://the-url.com/subdirectory/next 时,我收到 404 错误。我的 nginx 配置是:
location /subdirectory {
alias /path/to/index.html;
index index.html;
try_files $uri $uri/ /path/to/index.html;
}
【问题讨论】:
-
你找到解决办法了吗?
-
有人找到解决方案了吗?
-
有什么解决办法吗?
标签: react-router