nodejsを実行している単純なreactjs SPAを取得しようとしていますが、ルータが正常に動作しません。 私はcreate-react-appで新しいAppを作成し、npm install react-routerを追加しました。 マイpackage.jsonがreact-router with react-routerが動作しません。
{
"name": "App",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.5.0",
"react-dom": "^15.5.0",
"react-router": "^4.0.0"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
である私はちょうどインクルードはSRC/compoentsに別のフォルダ内のコンポーネント/ と私のindex.jsを反応置く
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App'
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
ReactDOM.render(
<App />,
document.getElementById('root')
);
これはとしてaspected作品です。アプリケーションが現れて、反応の世界の例が示されます。 しかし、私はルータ
<Router history={ hashHistory }>
<Route path='/' component={ App }/>
</Router>
アプリの休憩でアプリケーションを置き換えるとき。 IndexRouteを使用しても、Appは機能しません。
hasHistoryをbrowserHistoryまたはcreateMemoryHistoryに変更しても何も変更されません。
正しい方向にヒントを教えてください。私は何が欠けていますか?
アプリはどのように中断しますか?どのようなエラーが発生していますか? –
コンソールには、履歴が必要であるという警告が表示されます。TypeError:this.props.historyは未定義です。警告:失敗した小道具の種類:小道具の 'history'は' Router'で必須とマークされていますが、その値は 'undefined'です。 ルータ(index.js:8) – HexXx
pre-version 4.0の方法で 'react-router'を初期化しています。' 'react-router' 4.0をセットアップするための文書を確認してください。(https://reacttraining.com/反応ルータ/ Web /ガイド/クイックスタート)またはパッケージの古いバージョンにダウングレードする –