英文:
React routing is not working and always showing 404
问题
以下是您的内容的翻译:
我的项目是React + .NET。在开发过程中,路由器运行正常,但当我发布此应用并在本地运行时,React路由器无法正常工作。有时它能工作,下一次就无法工作,显示404错误页面。
这是React路由器的代码。我已将路由器更改为react-router,但它仍然无法正常工作。
英文:
My project is React + .NET. In development, the router is working fine, but when I publish this app and run it on local, react router is not working correctly. Once working, and next time never works and shows 404 error page.
<Routes>
<Route element={<Home isAuthorized={isAuthorized} />} path="/" />
<Route element={<SignIn />} path="/auth/sign-in" />
<Route element={<SignUp />} path="/auth/sign-up" />
{isAuthorized && (
<Route
element={<AccountSetting isAuthorized={true} />}
path="/auth/account-setting"
/>
)}
{isAuthorized && (
<Route
element={<Games isAuthorized={true} />}
path="/game/games"
/>
)}
<Route
element={<MainGame isAuthorized={isAuthorized} />}
path="/game/main-game"
/>
<Route element={<About />} path="/about" />
<Route element={<Features />} path="/landing/features" />
<Route element={<FreeTrial />} path="/landing/free-trial" />
</Routes>
This is the React route code. I've been changed router to react-router, but not working too.
答案1
得分: 0
I think problem is within your server-side.
我认为问题出在你的服务器端。
I'm sure you would use cors.
我确信你会使用 CORS。
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder =>
{
builder.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed((host) => true)
.AllowCredentials();
}));
app.UseCors("CorsPolicy");
Also check if your set MapFallbackToFile.
还要检查是否设置了 MapFallbackToFile。
app.MapFallbackToFile("index.html");
英文:
I think problem is within your server-side.
I'm sure you would use cors.
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder =>
{
builder.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed((host) => true)
.AllowCredentials();
}));
app.UseCors("CorsPolicy");
Also check if your set MapFallbackToFile.
app.MapFallbackToFile("index.html");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论