主动根据服务器路由更改

时间:2019-04-06 15:33:49

标签: reactjs websocket react-redux react-router

我正在使用带有Express和Websocket的服务器的客户端(react + redux)应用程序进行测验。

在此应用中,服务器需要确定需要显示的组件。 (通过更改路线)

(参见代码)

class App extends Component {

handleData(data) {
    console.log(data);
    return async dispatch => {
        dispatch(data)
    };
}

webSocketSend =(data) =>{
    this.refWebSocket.sendMessage(data);
}

render() {
    return (
            <div className="App">
                <Websocket url={`ws://localhost:3000/`} onMessage={this.handleData} ref={Websocket => {
                    this.refWebSocket = Websocket;}}/>
                <Nav/>
                <Switch>
                    <Route exact path="/" render={() => <SigninContent websocketSend={this.webSocketSend} /> } />
                    <Route path="/categoryselect" component={Categoryselect}/>
                    <Route path="/teamselect" component={Teamselect}/>
                    <Route path="/newround" component={Newround}/>
                    <Route path="/questionselect" component={Questionselect}/>
                    <Route path="/answerselect" component={Answerselect}/>
                    <Route path="/scorescreen" component={Scorescreen}/>
                </Switch>
            </div>
    );
}
}

export default App;

但是您认为让服务器使用redux处理路由更改的最佳方法是什么?

0 个答案:

没有答案