React-dom-router 版本 6 heroku
我试图为应该部署在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论