使用反应路由器 V6 和刷新页面时我得到空白页面

问题描述

我学习了 ReactJs,现在我无法理解这个问题。我发现 much 对此进行了讨论,但这都是针对低于 v6 的路由器。

在本地主机上它工作正常,但在实时服务器生产中它不工作如果我输入或刷新:

https://greta.portplays.com/app/login

我得到一个空白的白页。

请建议我知道这与历史有关,但路由器 v6 不要像其他解释一样使用它

这是我的路线没什么特别的:

import React from 'react';
import ContentLayout from './components/structure/ContentLayout';
import DashboardLayout from './components/DashboardLayout';
import AccountView from './components/DashboardLayout/views/account/AccountView';
import SearchListView from './components/DashboardLayout/views/search/SearchListView';
import DashboardView from './components/DashboardLayout/views/dashboard/DashboardView';
import NotFoundView from './components/DashboardLayout/views/errors/NotFoundView';
import CreateContentView from './components/DashboardLayout/views/creator/CreateContentView';
import SettingsView from './components/DashboardLayout/views/settings/SettingsView';
import LoginView from './components/DashboardLayout/views/auth/LoginView';
import RegisterView from './components/DashboardLayout/views/auth/RegisterView';
import SubmissionsView from './components/DashboardLayout/views/submissions/SubmissionsView';
import InBoxView from './components/DashboardLayout/views/inBox/InBoxView';

const routes = [
    {
        path: 'app',element: <DashboardLayout />,children: [
            { path: 'account',element: <AccountView /> },{ path: 'search',element: <SearchListView /> },{ path: 'dashboard',element: <DashboardView /> },{ path: 'create',element: <CreateContentView /> },{ path: 'submissions',element: <SubmissionsView /> },{ path: 'inBox',element: <InBoxView /> },{ path: 'settings',element: <SettingsView /> },{ path: 'login',element: <LoginView /> },{ path: 'register',element: <RegisterView /> },{ path: '*',element: <NotFoundView /> },{ path: '/',],},{
        path: '/',element: <ContentLayout />,children: [
            { path: '404',];

export default routes;

在 package.json 中我是这样添加

"homepage": "https://greta.portplays.com/",

也在我添加的应用程序的 Apache 服务器根目录中添加 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

我的应用位于这样的子域中:

enter image description here

解决方法

当本地存储被清除或 isUserAnon 设置为 false 时,似乎工作正常。

,

您需要在构建之前在 package.json 文件中进行更改。

{
  

  "devDependencies": {},"homepage": "<Your domain>","author": "",}

再次运行构建命令。

npm run build