您不应在<Router>外使用<Route>或withRouter(),而应在路由中使用Im

时间:2019-09-30 20:56:28

标签: javascript reactjs

我在BrowserRouter内部使用Route,但是仍然出现错误,我不确定自己做错了什么

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import {Provider} from 'react-redux';
import {BrowserRouter} from 'react-router-dom';

import App from './App/index';
import * as serviceWorker from './serviceWorker';
import reducer from './store/reducer';
import config from './config';

const store = createStore(reducer);

const app = (
    <Provider store={store}>
        <BrowserRouter basename={config.basename}>
            <App />
        </BrowserRouter>
    </Provider>
);

ReactDOM.render(app, document.getElementById('root'));

1 个答案:

答案 0 :(得分:0)

我认为您应该像这样使用withRouter()

export default withRouter(connect(mapStateToProps)(Something));

document可能对您有帮助