反应材料Ui和反应路由器

问题描述 投票:0回答:1

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

reactjs material-ui
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.