问题描述
我正在使用电子6.10.0和React.js.
I am using electron 6.10.0 and using React.js.
在我的应用中,菜单中有一个添加任务选项,它会创建一个新窗口.
In my app, there is an add task option in menu, which creates a new window.
在开发过程中一切正常,但是在生产过程中,这条线会引起问题.
Everything works fine during development, but during production this line causes problem.
addWindow.loadURL(isDev?'http://localhost:3000/add':`file://$ {path.join(__dirname,'../build/index.html')})`);
它加载index.html,通过它加载index.js并呈现router.js.这是Router.js中的代码.
It loads index.html, through which it loads index.js and which renders router.js. This is the code in Router.js.
<HashRouter>
<Switch>
<Route exact path="/" component={App} />
<Route exact path="/add" component={addWindow} />
</Switch>
</HashRouter>
Mainwindow可以正常工作,因为哈希是'/',但是对于添加窗口,哈希不会改变,它会在addwindow中再次加载mainwindow内容.
Mainwindow works fine because the hash is ' / ' but for add window the hash doesn't change and it loads the mainwindow content again in addwindow.
在生产过程中如何使用路由/路由器,或者还有其他方法.
How to use the route/Router during production, or is there any other way around.
谢谢.
推荐答案
好,我通过在链接末尾添加#/add来解决它,如下所示:
Ok, I solved it by adding #/add at the end of the link, like this:
addWindow.loadURL(isDev ?
'http://localhost:3000/add' :
`file://${path.join(__dirname, '../build/index.html#/add')}`);
这篇关于生产过程中如何在电子反应应用程序中进行路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!