React Material-UI with Router

后端 未结 2 1534
刺人心
刺人心 2021-01-21 07:35

I\'m trying to build simple React app using Material-UI library.
I\'ve used the example app for create-react-app and try to add Router to it so I can navigate between compon

2条回答
  •  走了就别回头了
    2021-01-21 08:26

    I have recently used material-ui and react-route-dom in my project. My project is using

    1.create-react-app [react 16.5.2]

    1. Material-UI [3.2.2]

    2. react-router-dom [4.3.2]

    index.js

    import { BrowserRouter } from 'react-router-dom';
    ReactDOM.render(, 
    document.getElementById('root'));
    

    App.js

    import React, { Component } from 'react';
    import ThemeDefault from './Theme/Theme';
    import Layout from './components/Layout/Layout';
    
    class App extends Component {
    
      render() {
        return (
          
            
          
        );
    }
    }
    
    export default App;
    

    Routes.js

    const ReactRouter = () => {
    return (
            
                
                    
                    
                    
                
            
    
       )
     }
     export default ReactRouter;
    

    Layout.js

         import ReactRouter from '../../routes';
           class Layout extends Component {
    
             render() {
              const { classes } = this.props;
    
              return (
                
    ) } } Layout.propTypes = { classes: PropTypes.object.isRequired, theme: PropTypes.object.isRequired, }; export default withStyles(styles, { withTheme: true })(Layout);

    In my example I am just updating part in main content. So I have added ReactRouter inside main in Layout.js

     
    will have app bar For side navigation menu
    will contain the different components content

提交回复
热议问题