function App(props) { const user = getCurrentUser() const isLoggedin = user ? true : false; return ( <React.Fragment> <Header user={user} /> <Switch> <Route path="/login" render={(props) => <LoginPage {...props} history={props.history} isLoggedin={isLoggedin}/>}></Route> <Route path="/logout" component={Logout} /> <Route path="/home" component={ProtectedRoute(HomePage, isLoggedin)} /> <Route path="/sources" component={ProtectedRoute(SourcesPage, isLoggedin)} /> <Route path="/not-found" component={ProtectedRoute(NotFoundPage, isLoggedin)} /> <Redirect from="/" exact to="/home" /> <Redirect to="/not-found" /> </Switch> </React.Fragment> ); }
else return renderProps(component || children || render, props); } else { const { state } = props.history.location; const newLocation = { pathname: redirectTo,
render() { const { previousLocation, data } = this.state; const { location } = this.props; const initialData = this.prefetcherCache[location.pathname] || data; return ( <RouteTransitioner location={location}> <Switch location={location}> {this.props.routes.map((r, i) => ( <Route key={`route--${i}`} path={r.path} exact={r.exact} location={previousLocation || location} render={(props) => React.createElement(r.component, { ...initialData, history: props.history, location: previousLocation || location, match: props.match, prefetch: this.prefetch, }) } /> ))} </Switch> </RouteTransitioner> ); }
user={this.state.user} chatrooms={this.state.chatrooms} onChangeUser={() => props.history.push('/user')} onEnterChatroom={ chatroomName => this.onEnterChatroom( chatroomName, () => props.history.push('/user'), chatHistory => props.history.push({ pathname: chatroomName, state: { chatHistory } render={ (props) => { const toHome = () => props.history.push('/') return this.renderUserSelectionOrRedirect(() => ( <UserSelection
user={this.state.user} chatrooms={this.state.chatrooms} onChangeUser={() => props.history.push('/user')} addChatRoom={() => this.addChatroom() } ref={(newRoom) => {this.newRoom = newRoom }} chatroomName => this.onEnterChatroom( chatroomName, () => props.history.push('/user'), chatHistory => props.history.push({ pathname: chatroomName, state: { chatHistory } render={ (props) => { const toHome = () => props.history.push('/') return this.renderUserSelectionOrRedirect(() => ( <UserSelection