简体   繁体   English

应用部署到生产服务器时返回 404

[英]App returns 404 when deployed to production server

My react app is working fine in local, but when I deploy it to a development server I cannot hit the refresh bar.我的反应应用程序在本地运行良好,但是当我将它部署到开发服务器时,我无法点击刷新栏。 If I do, it will immediately throw a 404 not found error.如果我这样做了,它会立即抛出 404 not found 错误。 I cannot manually navigate using the address bar.我无法使用地址栏手动导航。

I have tried modifying the .htaccess file in the server.我尝试修改服务器中的.htaccess文件。 still no luck.仍然没有运气。 I tried tinkering with the router adding browserhistory and stuff and still no luck.我尝试修补路由器添加browserhistory历史记录和其他东西,但仍然没有运气。 I understand this has something to do with client side routing .我知道这与client side routing有关。 This is the .htaccess file I'm currently using这是我目前使用的.htaccess文件

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

This is the generic code I'm using in App.js这是我在App.js中使用的通用代码

import React from "react";
import { Switch, Route,Link } from "react-router-dom";
import Backup from "./forms/backup_request/backupRequest";
import Restoration from "./forms/restoration_request/RestorationRequest";
import AssetRequest from "./forms/new_asset_request/AssetRequest";

class App extends React.Component {
render() {
return (
<div>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/backup_request" component={Backup} />
<Route path="/restoration_request" component={Restoration}/>
<Route path="/new_asset_request" component={AssetRequest} />
</div>
</Switch>
)
}
}

This is the error message displayed这是显示的错误消息

Not Found The requested URL /id_request was not found on this server.

fixed it.解决它。 it was a serverside error.这是一个服务器端错误。 needed configuring on the apache server to accept the .htaccess file.需要在 apache 服务器上进行配置以接受.htaccess文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在生产中部署反应应用程序时 CSS 不完整 - CSS not complete when react app deployed in production React Flask 应用程序可在 Docker 容器中运行,但在部署到 Cloud Run 时返回 404 错误 - React Flask app works in Docker container but returns 404 error when deployed to Cloud Run 部署的 React 应用程序显示一个空白页面并且控制台返回错误 404 - Deployed React App Shows a Blank Page and Console Returns Error 404 React 应用程序在部署到 heroku 时返回 HTTP 错误 404 - React app returning HTTP error 404 when deployed to heroku 刷新页面时出现404错误-部署在Heroku上的React App - 404 error when refreshing the page - React App deployed on Heroku 尝试登录部署在heroku上的应用程序时,auth0回调时出现404 - 404 on auth0 callback when trying to login on app deployed on heroku React 应用程序在部署到 GCP 时出现 404 错误 - React app giving 404 error when deployed to GCP Nginx 服务器在我的 React Router 应用程序中返回 404 - Nginx server returns 404 in my React Router app 在部署在 heroku 上的 MERN 应用程序上获取 404 - Getting 404 on a MERN App deployed on heroku 使用自定义Express服务器时,端点返回404 - Endpoint returns 404 when using custom Express server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM