没有教程,我找不到任何教程。所以我试图遵循"课程"在反应路由器文档上。让我们走看我所拥有的,也许你可以看到我出错的地方以及最佳解决方案。
React Router 4.2.0
让我们定义一些路线:
import { render } from 'react-dom';
import StartUp from './components/startup.js';
import { Router, Route, hashHistory } from 'react-router';
const Routes = (
<Router history={hashHistory}>
<Route path="/" component={StartUp} />
</Router>
);
render(
Routes,
document.getElementById('app')
);
让我们运行我们的应用程序,其基础index.js
)如下所示:
/* eslint strict: 0 */
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
let mainWindow = null;
require('electron-reload')(__dirname);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on('ready', () => {
mainWindow = new BrowserWindow({ width: 1024, height: 728 });
mainWindow.loadURL(`file://${__dirname}/src/index-electron.html`);
mainWindow.on('closed', () => {
mainWindow = null;
});
});
这都是使用webpack 3编译的,这对任何事情都很重要。因此,运行此控件时我在控制台中遇到的错误是:
bundle.js:572 Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
in RouterprintWarning @ bundle.js:572
bundle.js:913 Uncaught TypeError: Cannot read property 'location' of undefined
bundle.js:12196 The above error occurred in the <Router> component:
in Router
Consider adding an error boundary to your tree to customize error handling behavior.
bundle.js:16770 Uncaught TypeError: Cannot read property 'location' of undefined
我认为这是因为我实际上并不在浏览器中,而是在&#34;文件中#34;如file:// ...
那么使用React Router和Electron的最佳方式是什么,这样我就可以利用定义和重定向路由的功能。