生产过程中如何在电子反应应用程序中进行路由 [英] How to route in electron react app during production

查看:47
本文介绍了生产过程中如何在电子反应应用程序中进行路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用电子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')}`);

这篇关于生产过程中如何在电子反应应用程序中进行路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆