反应物料Ui和反应路由器

时间:2020-05-05 06:08:41

标签: reactjs material-ui

我的应用程序中有工具条和应用程序栏。我想使用Link(反应路由器)打开一个页面,该页面应该像普通的html页面一样没有appbar和sidebar即可打开。当前,它在侧边栏和应用栏的主体部分内打开。请帮忙。

1 个答案:

答案 0 :(得分:2)

如果我理解正确。 尝试:

// app.js
import React from 'react';
import {Switch, Route, withRouter} from 'react-router-dom';

import './App.css';

import Sidebar from './components/Sidebar';
import AppBar from './components/Appbar';

import Home from './pages/Home';
import Blog from './pages/Blog';

const App = (props) => {

  const pathname = props.location;

  // Just show up with this routes
  const configRoutes = ['/', '/about'];

  const checkPath = configRoutes.includes(pathname);

  return(
    <div className="App">
      {
        checkPath && (<Appbar />
        <Sidebar />)
      }


      <Switch>
        <Route path="/" exact component={Home} />
        <Route path="/blog" exact component={Blog} />
      </Switch>

    </div>
  );
}

export default withRouter(App);