使用React Router登出

时间:2019-09-11 17:25:03

标签: reactjs redux react-redux react-router

Redux在我的系统上正确编写了代码。但是我无法将它与React Router正确连接。这样,系统就会失败。

import React, { Component } from 'react'

import NAVBAR from './Components/Navbar'
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import * as ROUTES from './constants/routes';
import SignIn from './Components/SignIn'
import SignUp from './Components/SignUp'
import Home from './Components/Home'
import Notfound from './Components/Notfound'
import { connect } from 'react-redux'

export class App extends Component {
  render() {
    return (
      <BrowserRouter>
        <div>
          <NAVBAR/>
          <Switch>  
            <Route exact path={ROUTES.HOME} component={Home} />
            <Route path={ROUTES.SIGN_IN} component={SignIn} />
            <Route path={ROUTES.SIGN_UP} component={SignUp} />
            <Route path={ROUTES.SIGN_OUT} render={this.props.onUserOut} /> // this problem*emphasized text*
            <Route component={Notfound} />
          </Switch>
        </div>
      </BrowserRouter>
    )
  }
}

const mapDispatchToProps = () => {
  return{
    onUserOut: () => ({type:'USER_OUT'})
  }
}

export default connect(null, mapDispatchToProps )(App)

Redux在我的系统上正确编写了代码。但是我无法将它与React Router正确连接。这样,系统就会失败。

0 个答案:

没有答案