我在Apache2.4中使用了React 16.12.0。我似乎无法通过输入浏览器访问URL,即使我可以导航到一个URL。我把这个设置在我的App.js文件中.
<div className="auth-wrapper">
<div className="auth-inner">
<Switch>
<Route exact path="/" component={Map} />
<Route path="/add" component={Add} />
<Route path="/edit/:id" component={Edit} />
<Route path="/search" component={Search} />
<Route path="/nocoords" component={NoCoordsSearch} />
<Route
path="/directory-additions-updates/:id"
component={DirectoryAddUpdate}
/>
<Route
path="/directory-additions-updates/"
component={DirectoryAddUpdate}
/>
<Route path="/:coop_id/people" component={AddPerson} />
<Route path="/person/:id/edit" component={EditPerson} />
<Route path="/:coop_id/listpeople" component={ListPeople} />
</Switch>
</div>
</div>
我创建了这个.htaccess文件
cat /var/www/html/client/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
但是,虽然我可以导航到像"/search“这样的URL,但是当我在浏览器栏中输入它,或者在页面上单击”刷新“时,我会得到一个404。我还需要做些什么来配置我的应用程序,这样我就可以通过键入URL访问它了?
发布于 2021-10-02 18:45:39
有几件事出了问题。我的.htaccess文件与"index.html“文件不在同一个目录中,因此必须移动。
第二,需要将其添加到我的Apache虚拟配置中。
<Directory "/var/www/html/client/build/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
其中/var/www/html/client/build/是包含index.html文件的目录。
https://stackoverflow.com/questions/69354804
复制相似问题