简体   繁体   English

在登录页面上隐藏标题

[英]Hide header on Login page

I want to hide the header bar in the Login page and after a succesful login it should appear in the other pages i tried to make a class in the css so it hides the header but i couldn't find a way to disable it after a succesful login 我想在“登录”页面中隐藏标题栏,成功登录后,它应该出现在其他页面中,我试图在css中创建一个类,因此它隐藏了标题,但是我找不到在a之后禁用它的方法成功登录

import React, { Component } from 'react';
import './App.css';
import Authen from './Pages/Authen';
import Home from './Pages/Home';
import {
  BrowserRouter as Router,
  Route,
  Link
} from 'react-router-dom';
class App extends Component {


  render() {
    return (

  <div className="app">

    <Router>
    <div>
       <div className="hide">
      <ul>
        <li><Link to="/Home">Home</Link></li>
      </ul>
      </div>
      <Route exact path="/" component={Authen}/>
      <Route path="/Home" component={Home}/>
    </div>
  </Router>

  </div>

    );
  }
}

export default App;

the css : CSS:

.hide{
  display: none;
}

And this is how the page redirects from Authentication page to the home page. 这就是页面从“身份验证”页面重定向到主页的方式。 The login page is not in the same file as the router page : 登录页面与路由器页面不在同一文件中:

    Login = () => {
    const email = this.refs.email.value;
    const password = this.refs.password.value;
    console.log(email,password);

    const auth = firebase.auth();

    const promise = auth.signInWithEmailAndPassword(email, password);

    promise.then(user =>{
      var lout = document.getElementById('Login');

      lout.classList.remove('hide');
    });

    promise.catch(e =>{
      var err = e.message;
      console.log(err);
      this.setState({err: err});
    });
    firebase.auth().onAuthStateChanged((user) => {
  if (user) {
    console.log(user.uid);
 this.props.history.push('/Home')
  }
});
}

To me, your code is a little bit unclear because we can't see where you declare your header. 对我来说,您的代码有点不清楚,因为我们看不到您在哪里声明标头。 I can see a couple of way you can deal with your situation. 我可以看到几种处理您的情况的方法。

First, what I generally use is React Redux to control the state of my user, and with the state of your user you can render HTML depending if he is online or not. 首先,我通常使用React Redux来控制用户的状态,根据用户的状态,您可以根据用户是否在线来呈现HTML。 This is a snippet on how you could manage dynamic rendering with a variable. 这是有关如何使用变量管理动态渲染的摘要。

class App extends Component {
  render() {
    let header = user.LoggedIn ? <Header /> : null
    return (
      <div>
            {header}
      </div>
    );
  }
}

However, with the current state of your application, this may be unnecessary. 但是,对于您的应用程序的当前状态,这可能是不必要的。 If you only hide the header on your root page, why even bothering putting it in. Encapsulate it within your home page and call it a day. 如果您仅将标题隐藏在根页面上,那么为什么还要麻烦将其放入。将其封装在您的主页中,并称之为一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM