How to use React Router with Electron?

后端 未结 7 937
生来不讨喜
生来不讨喜 2020-12-14 00:08

Using this boilerplate as reference I created an Electron app. It uses webpack to bundle the scripts and express server to host it.

Webpack config is practically sam

7条回答
  •  孤城傲影
    2020-12-14 00:33

    Had to Replace BrowserRouter with HashRouter.

    import {
      HashRouter,
      Route
    } from "react-router-dom";
    

    And then in my index.js or the entry file of the Electron app I had something like this:

    
      

    And then everything just worked.

    The reasoning: BrowserRouter is meant for request-based environments whereas HashRouter is meant for file-based environments.

    Read more here:

    • https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/HashRouter.md

提交回复
热议问题