php - React-Router 的 BrowserHistory,无法直接访问
大家讲道理
大家讲道理 2017-06-05 11:07:46
0
1
820

有一个 React 项目使用了 BrowserHistory,放在了 Apache 服务器上,项目首页是localhost:8081/home。

我再进入主页之后可以跳转其他子页面(子路由),比如:localhost:8081/product

但是浏览器直接输入localhost:8081/product是访问不到的因为Apache服务器会解析这个路径

我只能localhost:8081/#/product来访问。

有什么办法直接访问吗?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
習慣沉默

将所有请求都转发到 index.html

配置 .htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
 </IfModule>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板