2017-09-03 47 views
0

我与阿波罗客户合作,反应,REAC routerv4和材料的UI响应appbar,我的应用程序工作, 插入材料的UI之前,我有与反应路由器V4,材料UI和阿波罗客户端选项

<Link to="/" className="navbar">React + GraphQL Tutorial</Link> 

,我已经插入材料的UI

<AppBar 
    title="Title" 
    iconClassNameRight="muidocs-icon-navigation-expand-more" 
    /> 

,但现在还不清楚,我如何与小屏幕添加链接的标题和选项,在响应模式,我认为一定是看不见的选项,在小屏幕上没有。 官方的材料ui网站没有很好地解释像bootstrap的例子,所以我需要一个帮助litlle。

完整的代码是:

import React, { Component } from 'react'; 
import { 
    BrowserRouter, 
    Link, 
    Route, 
    Switch, 
} from 'react-router-dom'; 

import './App.css'; 
import ChannelsListWithData from './components/ChannelsListWithData'; 
import NotFound from './components/NotFound'; 
import ChannelDetails from './components/ChannelDetails'; 
import AppBar from 'material-ui/AppBar'; 
import getMuiTheme from 'material-ui/styles/getMuiTheme'; 
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; 

import { 
    ApolloClient, 
    ApolloProvider, 
    createNetworkInterface, 
    toIdValue, 
} from 'react-apollo'; 


const networkInterface = createNetworkInterface({ uri: 'http://localhost:4000/graphql' }); 
networkInterface.use([{ 
    applyMiddleware(req, next) { 
    setTimeout(next, 500); 
    }, 
}]); 

function dataIdFromObject (result) { 
    if (result.__typename) { 
    if (result.id !== undefined) { 
     return `${result.__typename}:${result.id}`; 
    } 
    } 
    return null; 
} 

// customResolvers: 
// This custom resolver tells Apollo Client to check its cache for a Channel object with ID $channelId 
// whenever we make a channel query. If it finds a channel with that ID in the cache, 
// it will not make a request to the server. 

const client = new ApolloClient({ 
    networkInterface, 
    customResolvers: { 
     Query: { 
      channel: (_, args) => { 
       return toIdValue(dataIdFromObject({ __typename: 'Channel', id: args['id'] })) 
      }, 
     }, 
    }, 
    dataIdFromObject, 
}); 


class App extends Component { 
    render() { 
    return (
     <ApolloProvider client={client}> 
     <BrowserRouter> 
      <MuiThemeProvider muiTheme={getMuiTheme()}> 
      <div className="App"> 
       <Link to="/" className="navbar">React + GraphQL Tutorial</Link> 
       <AppBar 
       title="Title" 
       iconClassNameRight="muidocs-icon-navigation-expand-more" 
       /> 
       <Switch> 
       <Route exact path="/" component={ChannelsListWithData}/> 
       <Route path="/channel/:channelId" component={ChannelDetails}/> 
       <Route component={ NotFound }/> 
       </Switch> 
      </div> 
      </MuiThemeProvider> 
     </BrowserRouter> 
     </ApolloProvider> 
    ); 
    } 
} 

export default App; 

回答

0

右边是添加一个这样的代码:

  <AppBar position="static"> 
      <Toolbar> 
       <IconButton color="contrast" aria-label="Menu"> 

       </IconButton> 
       <Typography type="title" color="inherit" > 
       {"Admin"} 
       </Typography> 
       <AuthLink to="/customers" label="Customers"/> 
       <AuthLink to="/tours" label="Tours"/> 
       <AuthLink to="/signout" label="Sign Out"/> 
       <AuthLink to="/signin" label=" Sign In" whenLogged="false"/> 
      </Toolbar> 
      </AppBar> 

Authlink仅仅是我写的,显示选项的组成部分,在那里简单我添加标题显示选项。

const AuthLink = (props) => { 
    let auth = checkAuth(); 
    return (
    ((auth && !props.whenLogged) || (!auth && props.whenLogged == "false") ) ? (
     <Link to={props.to} className="navbar"><Button>{props.label}</Button></Link> 
    ) : (
     null 
    ) 
); 
} 

“按钮” 是从材料的成分, “链接” 从反应路由器,这里的进口:

import { 
    BrowserRouter, 
    Link, 
    Route, 
    Switch, 
    Redirect, 
} from 'react-router-dom'; 

import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles'; 
import AppBar from 'material-ui/AppBar'; 
import Toolbar from 'material-ui/Toolbar'; 
import Typography from 'material-ui/Typography'; 
import Button from 'material-ui/Button'; 
import IconButton from 'material-ui/IconButton';