使用 React Router V6 并在刷新页面时出现空白页面

Using react router V6 and when refresh page I get blank page

我是学ReactJs的,现在看不懂这个问题。我发现 对此进行了讨论,但这都是针对低于 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: '/', element: <DashboardView /> },
        ],
    },
    {
        path: '/',
        element: <ContentLayout />,
        children: [
            { path: '404', element: <NotFoundView /> },
            { path: '*', element: <NotFoundView /> },
        ],
    },
];

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>

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

您需要在构建前更改 package.json 文件。

{
  

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

运行 再次构建命令。

npm run build

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