URL dependent labeling of the toolbar
This commit is contained in:
		
							parent
							
								
									baa047f8d7
								
							
						
					
					
						commit
						f38a33fd4a
					
				| @ -4,6 +4,8 @@ import { Link } from 'react-router-dom'; | |||||||
| import ClearWorkspace from './ClearWorkspace'; | import ClearWorkspace from './ClearWorkspace'; | ||||||
| import senseboxLogo from './sensebox_logo.svg'; | import senseboxLogo from './sensebox_logo.svg'; | ||||||
| 
 | 
 | ||||||
|  | import { withRouter } from 'react-router-dom'; | ||||||
|  | 
 | ||||||
| import { withStyles } from '@material-ui/core/styles'; | import { withStyles } from '@material-ui/core/styles'; | ||||||
| import Drawer from '@material-ui/core/Drawer'; | import Drawer from '@material-ui/core/Drawer'; | ||||||
| import AppBar from '@material-ui/core/AppBar'; | import AppBar from '@material-ui/core/AppBar'; | ||||||
| @ -68,6 +70,12 @@ class Navbar extends Component { | |||||||
|             <Link to={"/"} style={{marginLeft: '10px'}}> |             <Link to={"/"} style={{marginLeft: '10px'}}> | ||||||
|               <img src={senseboxLogo} alt="senseBox-Logo" width="30"/> |               <img src={senseboxLogo} alt="senseBox-Logo" width="30"/> | ||||||
|             </Link> |             </Link> | ||||||
|  |             {/^\/tutorial(\/.*$|$)/g.test(this.props.location.pathname) ? | ||||||
|  |               <Link to={"/tutorial"} style={{textDecoration: 'none', color: 'inherit', marginLeft: '10px'}}> | ||||||
|  |                 <Typography variant="h6" noWrap> | ||||||
|  |                   Tutorial | ||||||
|  |                 </Typography> | ||||||
|  |               </Link> : null} | ||||||
|           </Toolbar> |           </Toolbar> | ||||||
|         </AppBar> |         </AppBar> | ||||||
|         <Drawer |         <Drawer | ||||||
| @ -90,10 +98,12 @@ class Navbar extends Component { | |||||||
|           </div> |           </div> | ||||||
|           <List> |           <List> | ||||||
|             {[{text: 'Tutorials', icon: faChalkboardTeacher}, {text: 'Einstellungen', icon: faCog}].map((item, index) => ( |             {[{text: 'Tutorials', icon: faChalkboardTeacher}, {text: 'Einstellungen', icon: faCog}].map((item, index) => ( | ||||||
|               <ListItem button key={index} onClick={this.toggleDrawer}> |               <Link to={"/tutorial"} style={{textDecoration: 'none', color: 'inherit'}}> | ||||||
|                 <ListItemIcon><FontAwesomeIcon icon={item.icon}/></ListItemIcon> |                 <ListItem button key={index} onClick={this.toggleDrawer}> | ||||||
|                 <ListItemText primary={item.text} /> |                   <ListItemIcon><FontAwesomeIcon icon={item.icon}/></ListItemIcon> | ||||||
|               </ListItem> |                   <ListItemText primary={item.text} /> | ||||||
|  |                 </ListItem> | ||||||
|  |               </Link> | ||||||
|             ))} |             ))} | ||||||
|             <ClearWorkspace onClick={this.toggleDrawer}/> |             <ClearWorkspace onClick={this.toggleDrawer}/> | ||||||
|           </List> |           </List> | ||||||
| @ -112,4 +122,4 @@ class Navbar extends Component { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default withStyles(styles, {withTheme: true})(Navbar); | export default withStyles(styles, {withTheme: true})(withRouter(Navbar)); | ||||||
|  | |||||||
| @ -3,6 +3,8 @@ import React, { Component } from 'react'; | |||||||
| import { Route, Switch } from 'react-router-dom'; | import { Route, Switch } from 'react-router-dom'; | ||||||
| 
 | 
 | ||||||
| import Home from './Home'; | import Home from './Home'; | ||||||
|  | import Tutorial from './Tutorial/Tutorial'; | ||||||
|  | import TutorialHome from './Tutorial/TutorialHome'; | ||||||
| import NotFound from './NotFound'; | import NotFound from './NotFound'; | ||||||
| 
 | 
 | ||||||
| class Routes extends Component { | class Routes extends Component { | ||||||
| @ -12,6 +14,8 @@ class Routes extends Component { | |||||||
|       <div style={{ margin: '0 22px' }}> |       <div style={{ margin: '0 22px' }}> | ||||||
|         <Switch> |         <Switch> | ||||||
|           <Route path="/" exact component={Home} /> |           <Route path="/" exact component={Home} /> | ||||||
|  |           <Route path="/tutorial" exact component={TutorialHome} /> | ||||||
|  |           <Route path="/tutorial/:tutorialId" exact component={Tutorial} /> | ||||||
|           <Route component={NotFound} /> |           <Route component={NotFound} /> | ||||||
|         </Switch> |         </Switch> | ||||||
|       </div> |       </div> | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								src/components/Tutorial/Tutorial.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/components/Tutorial/Tutorial.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | import React, { Component } from 'react'; | ||||||
|  | 
 | ||||||
|  | import { withRouter } from 'react-router-dom'; | ||||||
|  | 
 | ||||||
|  | class Tutorial extends Component { | ||||||
|  |   render() { | ||||||
|  |     console.log(this.props); | ||||||
|  |     return ( | ||||||
|  |       <h1>Tutorial {this.props.match.params.tutorialId}</h1> | ||||||
|  |     ); | ||||||
|  |   }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export default withRouter(Tutorial); | ||||||
							
								
								
									
										11
									
								
								src/components/Tutorial/TutorialHome.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/components/Tutorial/TutorialHome.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | |||||||
|  | import React, { Component } from 'react'; | ||||||
|  | 
 | ||||||
|  | class TutorialHome extends Component { | ||||||
|  |   render() { | ||||||
|  |     return ( | ||||||
|  |       <h1>Tutorial Home</h1> | ||||||
|  |     ); | ||||||
|  |   }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export default TutorialHome; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user