Apache 2.4 + React Router 4 总是路由到我的 404 页面组件
Apache 2.4 + React Router 4 always routing to my 404 page component
我无法让我的 create React 应用构建正确路由到我服务器上的组件。
我有一个 .htaccess 文件
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
所以它总是路由到我的 index.html
我网站的 url 是 .com/project,我的 package.json 文件中的主页选项是 homepage: '/project'
我 运行 没有事情要做。
因为我的 htaccess 它总是路由到我的 index.html 但路由器总是加载 404 组件。我错过了什么。
发生这种情况是因为基本路由错误,因此一直路由到 404 页面。
设置 <Router basename="/<Directory>">
并将主页选项添加到我的 package.json 文件解决了这个问题。
我使用这个 .htaccess:
RewriteEngine On
RewriteBase /project
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.html? [L,QSA]
我无法让我的 create React 应用构建正确路由到我服务器上的组件。
我有一个 .htaccess 文件
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
所以它总是路由到我的 index.html
我网站的 url 是 .com/project,我的 package.json 文件中的主页选项是 homepage: '/project'
我 运行 没有事情要做。
因为我的 htaccess 它总是路由到我的 index.html 但路由器总是加载 404 组件。我错过了什么。
发生这种情况是因为基本路由错误,因此一直路由到 404 页面。
设置 <Router basename="/<Directory>">
并将主页选项添加到我的 package.json 文件解决了这个问题。
我使用这个 .htaccess:
RewriteEngine On
RewriteBase /project
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.html? [L,QSA]