我在Cory House的pluralsight course之後關於在ES6中構建React。不幸的是,我陷入了第一個步驟之一,設置了基本的組件。找不到模塊:錯誤:無法解析模塊「路線」
在我看到下面的錯誤信息控制檯:
Warning: [react-router] Location "/" did not match any routes
如果我看在我開發服務器我看到下面的
ERROR in ./src/index.js
Warning: [react-router] Location "/" did not match any routes
然後在下面,我看到eslint已經踢出以下錯誤:
C:\Projects\es6react\src\index.js (1/0)
✖ 5:9 routes not found in './routes' import/named
所以這個應該非常簡單。然而,看着我的目錄結構,index.js
文件和routes.js
沒有什麼突出的......即使大約30分鐘後。
index.js
import 'babel-polyfill';
import React from 'react';
import {render} from 'react-dom';
import {Router, browserHistory} from 'react-router';
import {routes} from './routes';
import './styles/styles.css';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
render(
<Router history={browserHistory} routes={routes} />,
document.getElementById('app')
);
routes.js
import React from 'react';
import {Route,IndexRoute} from 'react-router';
import App from './components/App';
import HomePage from './components/home/HomePage';
import AboutPage from './components/about/AboutPage';
export default(
<Route path="/" component={App}>
<IndexRoute component={HomePage} />
<Route path="about" component={AboutPage}/>
</Route>
);
目錄結構
而且萬一我的scripts
部分從我package.json
:
"scripts": {
"prestart": "babel-node tools/startMessage.js",
"start": "npm-run-all --parallel open:src lint:watch test:watch",
"open:src":"babel-node tools/srcServer.js",
"lint": "node_modules/.bin/esw webpack.config.* src tools",
"lint:watch": "npm run lint -- --watch",
"test":"mocha --reporter progress tools/testSetup.js \"src/**/*.test.js\"",
"test:watch": "npm run test -- --watch"
},
就在我的面前......謝謝 – NealR
歡迎您:) – madox2