尝试使react-router-dom和react-redux很好地播放,但是在浏览器控制台中出现以下错误:
警告:React.createElement:type无效 - 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:undefined。您可能忘记从其定义的文件中导出组件。
index.js
import React from 'react';
import ReactDom from 'react-dom';
import Provider from 'react-redux';
import { createStore } from 'redux';
import reducer from './src/reducers/Index';
import Root from './src/views/Root';
let store = createStore(reducer)
ReactDom.render(
<Provider store={store}>
<Root />
</Provider>,
document.getElementById('content')
);
reducer(Index.js)
import {combineReducers} from 'redux';
import Login from './Login';
export default combineReducers({
Login
})
reducer(Login.js)
export default function login(state = 'Login', action) {
switch (action.type) {
case 'LOGINLOADING':
return state + 1
case 'LOGINLOADED':
return state - 1
default:
return state
}
}
Root.js
import React from 'react';
import BrowserRouter from 'react-router-dom';
import App from './App';
class Root extends React.Component {
render(){
return (
<BrowserRouter>
<App />
</BrowserRouter>
);
}
}
export default Root;
App.js
import React from 'react';
class App extends React.Component {
render(){
return (
<div>
<p> Hello Kitty </p>
</div>
);
}
}
export default App;
答案 0 :(得分:0)
对不起我修好了。
import {createStore} from 'redux';
到
import createStore from 'redux';
答案 1 :(得分:0)
import BrowserRouter from 'react-router-dom';
请注意,BrowserRouter不是react-router-dom
软件包的默认导出。
因此,您需要使用花括号将其声明:
import { BrowserRouter } from 'react-router-dom';