【问题标题】:React router v6 crashes on refreshingReact 路由器 v6 在刷新时崩溃
【发布时间】:2021-01-16 00:55:48
【问题描述】:

我正在使用 react-router v6 它在开发模式下工作正常(刷新网站时不会崩溃并且工作正常)但在生产中当我刷新网站崩溃时导航很好

我的代码是,


import {
  BrowserRouter as Router,
  Route,
  Routes
} from "react-router-dom";
//all the import of components

function App() {
  return (
    <div className="App">
      <Router>
        <Navbar />
        <Routes>
          <Route path="/" element={<Home></Home>} />
          <Route exact path="/shop" element={<Shop></Shop>} />
          <Route path="/shop/:slug" element={<Product />} />
          <Route path="/cart" element={<Cart></Cart>} />
          <Route path="*" element={<h1>not found</h1>} />
        </Routes>
      </Router>

    </div>
  );
}

【问题讨论】:

    标签: react-redux react-router react-router-dom


    【解决方案1】:

    这是 Netlify 的一个问题,当我在 Vercel 上部署它时它运行良好。

    【讨论】:

      【解决方案2】:

      我有同样的问题,对我来说,有助于在公用文件夹中创建带有 /* /index.html 200 内容的 _redirects 文件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-20
        • 1970-01-01
        • 2019-09-16
        • 1970-01-01
        • 1970-01-01
        • 2022-11-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多