reactjs - Electron - React - React Router 加载自定义路由(例如:example.com/#/popup)
问题描述
我在搞乱反应,反应路由器和电子,我创建了一个像这样的简单路由器:
export const Router: FC = () => {
return (
<HashRouter>
<Switch>
<Route exact path="/">
<IndexPage />
</Route>
<Route path="/stats">
<StatsPage />
</Route>
<Route path="/popup">
<PopupPage />
</Route>
</Switch>
</HashRouter>
);
};
我可以在浏览器和电子应用程序上看到所有路线,没有问题,但有问题。如何/popup
直接加载页面<ElectronBrowserWindow>.loadURL();
?这是我所拥有的:
popupWindow = new BrowserWindow({
width: 260,
height: 360,
x: 0,
y: 0,
resizable: false,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
devTools: false,
contextIsolation: false,
},
frame: false,
icon,
title: "Brawlhalla Stats",
});
popupWindow.loadURL(
isDev
? "http://localhost:3000/#/popup" // this one works
: `file://${path.join(__dirname, "../build/index.html?#/popup")}`, // this one not
);
感谢您的所有帮助:3
解决方案
好吧,我只是环顾四周,发现了同样的帖子:Get Electron production window to load a route with loadURL?
这是@IronWaffleMan 的回答:https ://stackoverflow.com/a/65068333/10124281
基本上,我只需要输入file://${path.join(__dirname, "../build/index.html#popup")}
推荐阅读
- javascript - 内部网站以某种方式破坏了浏览器配置文件
- python - 合并具有相同标题名称的列
- postgresql - PostgreSQL:调整子项的外键以删除父项中的重复项
- postgresql - 将 PowerPoint、PDF 和此类文档文件保存到 Postgres 数据库
- python - 从光谱中提取参数
- android - Android 使用 ImageView 发布图像和显示响应
- javascript - 将 ajax POST 与 codeigniter 一起使用的问题
- javascript - Ajax - 将数据发布到多个页面
- cocoa - Siri 快捷方式和 CocoaPods - 未找到文件
- mysql - 使用 IN(SELECT....) mySQL 查询时没有返回结果