Javascript 未找到模块:错误:无法解析模块';路线';
我正在关注Cory House在ES6中的建筑反应。不幸的是,我还停留在最初的几个步骤之一,即设置基本组件 在控制台中,我看到以下错误消息:Javascript 未找到模块:错误:无法解析模块';路线';,javascript,node.js,reactjs,react-router,react-redux,Javascript,Node.js,Reactjs,React Router,React Redux,我正在关注Cory House在ES6中的建筑反应。不幸的是,我还停留在最初的几个步骤之一,即设置基本组件 在控制台中,我看到以下错误消息: Warning: [react-router] Location "/" did not match any routes 如果我查看我的开发服务器,我会看到以下内容 ./src/index.js中出现错误 警告:[反应路由器]位置“/”与任何路由都不匹配 下面我看到eslint排除了以下错误: C:\Projects\es6react\src\inde
Warning: [react-router] Location "/" did not match any routes
如果我查看我的开发服务器,我会看到以下内容
./src/index.js中出现错误
警告:[反应路由器]位置“/”与任何路由都不匹配
下面我看到eslint排除了以下错误:
C:\Projects\es6react\src\index.js(1/0)
✖ 5:9在“./routes”导入/命名中未找到路由
所以这应该很简单。然而,看看我的目录结构,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')
);
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>
);
如果使用默认导出,则需要将其作为默认值导入(不带花括号): 另一方面,您可以使用命名导出并按名称导入:
// index.js
export const routes = ...
// routes.js
import {routes} from './routes';
因为您正在从
routes.js
未命名导出的文件执行默认导出,并将其作为命名导出导入
使用以下命令:
import routes from './routes'; //remove {}
您在routes.js中使用了“导出默认值”,这意味着要导入它,您需要使用: 从“/routes”导入路由 在您的代码中,您使用了{routes},在没有默认值的情况下导出时将导入
// index.js
export const routes = ...
// routes.js
import {routes} from './routes';
import routes from './routes'; //remove {}