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