Material-UI's Tabs integration with react router 4?

后端 未结 9 2057
一个人的身影
一个人的身影 2020-12-24 10:58

The new react-router syntax uses the Link component to move around the routes. But how could this be integrated with material-ui?

In my cas

9条回答
  •  生来不讨喜
    2020-12-24 11:12

    My instructor helped me with using React Router 4.0's withRouter to wrap the Tabs component to enable history methods like so:

    import React, {Component} from "react";
    import {Tabs, Tab} from 'material-ui';
    import { withRouter } from "react-router-dom";
    
    import Home from "./Home";
    import Portfolio from "./Portfolio";
    
    class NavTabs extends Component {
    
     handleCallToRouter = (value) => {
       this.props.history.push(value);
     }
    
      render () {
         return (
          
            
            
    ) } } export default withRouter(NavTabs)

    Simply add BrowserRouter to index.js and you're good to go.

提交回复
热议问题