我正在尝试使用react-router的基本名称,如react-router docs中所记录的那样.这是由于基础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')
);Run Code Online (Sandbox Code Playgroud)
当我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;
}
Run Code Online (Sandbox Code Playgroud) react-router ×1