使用React和Electron - reaction -router错误
Using React and Electron - react-router error
我刚开始学习如何用电子制作桌面应用程序,我试图用电子使用react-router,但我一直得到错误Warning: [react-router] Location "/" did not match any routes
main.js
app.on('ready', () => {
win = new BrowserWindow({width: 800, height: 600});
win.loadURL(`file://${__dirname}/index.html`);
win.webContents.openDevTools();
win.on('closed', () => win = null);
})
routes.js
import App from './app';
import { Router, Route, hashHistory } from 'react-router';
import React from 'react';
const routes = (
<Router>
<Route path="/" component={App}/>
</Router>
);
index.js
import ReactDOM from 'react-dom';
import React from 'react';
import { Router, hashHistory } from 'react-router';
import routes from './routes';
ReactDOM.render(<Router routes={routes} history={hashHistory}/>, document.getElementById('app'));
app.js
import React, { Component } from 'react';
export default class App extends React.Component {
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
我能做些什么来解决这个问题?
没注意到。你在routes.js中声明了你的路由器,然后在index中声明了另一个路由器,将路由作为prop传递。
我认为你应该修改你的routes.js(你必须导出你的routes const)。
路线:
import App from './app';
import { Router, Route, hashHistory } from 'react-router';
import React from 'react';
const routes = (
<Router history={hashHistory}>
<Route path="/" component={App}/>
</Router>
);
module.exports = routes;
现在你可以把它导入到你的索引中,你应该直接渲染你的路由:
import ReactDOM from 'react-dom';
import React from 'react';
import { Router, hashHistory } from 'react-router';
import routes from './routes';
ReactDOM.render(routes, document.getElementById('app'));
你试过把历史道具在路由器吗?
<Router history={hashHistory}>
相关文章:
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- this.router在AngularJS 2中未定义
- Meteor Router数据函数被调用两次
- 如何在router.get()方法中传递url作为参数
- renderReact/Rect Router+Node/Express.js的服务器端/同构渲染中未定义renderP
- 骨干's Router.execute(callback,args,name)方法获取未定义的名称
- 有没有办法用routerLink/router.navigation附加查询/路由参数
- react router router.HistoryLocation以<noscript>但没有完美的工作
- 使用express.具有多个url和可选参数的Router()
- 单击同一链接时,使Iron Router重新加载页面
- React Router一直给我一个警告:你不能更改<路由器路由>
- BackboneJs Router
- Ember.js-如何使用Ember.Router实现所选项目
- 使用react router/react router redux将特定的redux操作绑定到一个路由
- Angular JS/UI Router:为给定状态禁用指令
- 使用AngularJS中的$stateProvider和ui.router
- 组件未使用ReactJS和React Router进行渲染
- React Router,在params之后嵌套路由
- Express router.use not working
- 使用React和Electron - reaction -router错误