React-dom-router 版本 6 heroku

发布于 2025-01-10 08:15:17 字数 1121 浏览 0 评论 0原文

我试图为应该部署在 Heroku 上的 React 应用程序创建嵌套路由。我有一个包含几行代码的 static.js:

{
    "root": "build/",
    "routes": {
      "/**": "index.html",
      "/posts/**": "index.html",

    }
  }

应用程序组件如下:


import { BrowserRouter, Routes, Route } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import { GetPosts } from "./store/services/DataSource";

import Home from "./Home";
import Posts from "./posts/Posts";
import Dashboard from './posts/Dashboard';

function App() {

  return (
    <BrowserRouter>
      <div className="App">
        <Navbarpage />
        <Routes>
          <Route path="posts" element={<Posts />}>
            <Route path="dashboard" element={<Dashboard />} />
          </Route>
        </Routes>
      </div>
    </BrowserRouter>
  );
}

export default App;

该应用程序在本地主机上完美运行,但只有当仪表板组件的路由被删除时,它才能在 Heroku 上运行。我不知道如何为 Heroku 上的 React 部署制作嵌套路由

您对问题的建议和解释将不胜感激。

谢谢。

I was trying to create nested routes for react app that should be deployed on Heroku. I have a static.js with lines of codes:

{
    "root": "build/",
    "routes": {
      "/**": "index.html",
      "/posts/**": "index.html",

    }
  }

The app component as follows:


import { BrowserRouter, Routes, Route } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import { GetPosts } from "./store/services/DataSource";

import Home from "./Home";
import Posts from "./posts/Posts";
import Dashboard from './posts/Dashboard';

function App() {

  return (
    <BrowserRouter>
      <div className="App">
        <Navbarpage />
        <Routes>
          <Route path="posts" element={<Posts />}>
            <Route path="dashboard" element={<Dashboard />} />
          </Route>
        </Routes>
      </div>
    </BrowserRouter>
  );
}

export default App;

The app works perfectly on localhost, but it worked on Heroku only if the route for Dashboard component was removed. I do not know how to make nested routes for React deployment on Heroku

Your suggestion and explanation for the problem would really be appreciated.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文