小编aar*_*ron的帖子

基本名称无法正常工作

我正在尝试使用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

10
推荐指数
2
解决办法
5086
查看次数

标签 统计

react-router ×1