Как оставить navbar вне определенной страницы? Реагировать на веб - PullRequest
0 голосов
/ 17 апреля 2020

** Как не отображать навигационную панель на страницах, результаты 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>
);

}}

1 Ответ

0 голосов
/ 17 апреля 2020
this.props.location returns currently opened url.

, так что вы можете проверить текущий URL и условно отобразить NavBar. если текущий URL-адрес равен тем URL-адресам, в которых вы не хотите показывать navbar, возвращайте null, иначе возвращайте navbar

<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>
     .
     .
     .
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...