問(wèn)題描述
使用 這個(gè)樣板 作為參考,我創(chuàng)建了一個(gè) 電子應(yīng)用.它使用 webpack 來(lái)打包腳本并使用 express server 來(lái)托管它.
Using this boilerplate as reference I created an Electron app. It uses webpack to bundle the scripts and express server to host it.
Webpack 配置實(shí)際上與 this 和服務(wù)器相同這個(gè).
Webpack config is practically same as this and server this.
Electron 的腳本加載:
Electron's script loads:
mainWindow.loadURL('file://' + __dirname + '/app/index.html');
并且 index.html 會(huì)加載服務(wù)器托管的腳本:
And index.html loads the script hosted by the server:
<script src="http://localhost:3000/dist/bundle.js"></script>
我運(yùn)行 electron index.js
來(lái)構(gòu)建應(yīng)用程序和 node server
來(lái)啟動(dòng)使用 webpack 捆綁腳本的服務(wù)器.
I run electron index.js
to build the app and node server
to start server which using webpack bundles the scripts.
它工作正常,我的 React 組件 App 已安裝.但是我如何將 react-router 集成到其中呢?
It works fine, my React component App is mounted. But how I integrate react-router into this?
我以與在瀏覽器應(yīng)用程序中相同的方式實(shí)現(xiàn)它.我收到此錯(cuò)誤:
I implemented it the same way I would in a browser app. I get this error:
[react-router] 位置/Users/arjun/Documents/Github/electron-app/app/index.html"沒(méi)有匹配任何路由
它以文件路徑為路徑.瀏覽樣板代碼并沒(méi)有幫助.我錯(cuò)過(guò)了什么?
It is taking file path as the route. Going through the boiler plate code did not help. What am I missing?
推薦答案
另一種選擇是使用 hashHistory.實(shí)際上,在您引用的回購(gòu) 您可以看到他們正在使用 hashHistory,要不要嘗試并回帖?
Another option would be to use hashHistory instead. Actually, in your referenced repo you can see that they're using hashHistory, how about trying that and posting back?
這篇關(guān)于如何將 React Router 與 Electron 一起使用?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!