2016-10-09 14 views
1

私はちょうどElectronでデスクトップアプリケーションを作るために、私は電子と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> 
    ); 
    } 
} 

私はこれを修正するために何ができますか?

+0

あなたはこれを解決しましたか? – Kafo

+0

@HusseinAlkafはい、私は、より具体的に表現するために、ノードのサーバーを作成しなければならなかった – corasan

答えて

0

ルーターに履歴用の小道具を置こうとしましたか?

<Router history={hashHistory}> 
+0

うん、私のための歴史のいずれかではありません。ありがとうございました :) – corasan

0

注目されませんでした。あなたはroutes.jsであなたのルータを宣言しています、そして、あなたはpropとしてルートを渡す別のルータを宣言しています。

私はあなたのroutes.jsを変更する必要があると思う(あなたのルート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')); 
関連する問題