如何将导航栏移出某些页面? React web

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

**如何在所有其他页面中显示导航栏而不在页面结果1-5中显示导航栏,是否可以在此文件中对其进行更改? **

  <BrowserRouter>
    <div>
      <Navbar />
      <Switch>
        <Route path="/" component={Home} exact />
        <Route path="/Aboutus" component={Aboutus} />
        <Route path="/Contactus" component={ContactUs} />



        <Route path="/selecttemplate" component={SelectT} />
        }/>
        }/>
        }/>
      </Switch>
    </div>
    <Route path="/result1" component={Result1} />
    <Route className='FullHeight' path="/result2" component={Result2} />
    <Route className='FullHeight' path="/result3" component={Result3} />
    <Route className='FullHeight' path="/result4" component={Result4} />
    <Route className='FullHeight' path="/result5" component={Result5} />
  </BrowserRouter>
);

}}

javascript html reactjs routing
1个回答
0
投票
this.props.location returns currently opened url.
因此您可以检查当前网址并有条件地渲染NavBar。如果当前网址等于您不想显示导航栏的那些网址,则返回null,否则返回导航栏

<BrowserRouter> <div> { ((this.props.history.location === '/') || (this.props.location === '/Aboutus') || (this.props.history.location === '/Contactus') || (this.props.history.location === '/selecttemplate') || (this.props.history.location === '/result1')) ? null : <Navbar /> } <Switch> . . .

© www.soinside.com 2019 - 2024. All rights reserved.