【问题标题】:React-router doesn't work well when loaded from a route instead of the home pageReact-router doesn\'t work well when loaded from a route instead of the home page
【发布时间】:2022-12-01 22:56:11
【问题描述】:

We're using react 16.13 and react-router-dom 5.1.2 but we struggle to make it work the way we want:

(We've configured the nodejs/express backend to send the react app no matter the route)

So react-router just adds all the history / path to the /page1 url, resulting in /page1/login, /page1/page1, etc. instead of the /login or /page1 urls.

Is there any way to achieve that? The goal is to allow the refresh of the page, and to allow direct access to a specific route.

Thanks

【问题讨论】:

    标签: node.js reactjs express react-router react-router-dom


    【解决方案1】:

    You need to use Routes rather than Switch for react-router-dom@6. Something like this:

        <BrowserRouter>
            <Routes>
              <Route path="/" element={<App />}>
              </Route>
            </Routes>
          </BrowserRouter>
    

    【讨论】:

      猜你喜欢
      • 2022-12-27
      • 2022-12-27
      • 2022-12-01
      • 2022-12-27
      • 2022-12-27
      • 2022-12-27
      • 2013-08-14
      • 2022-12-01
      • 2022-12-02
      相关资源
      最近更新 更多