首页 > 解决方案 > 如何将信息从控制器传递到局部视图

问题描述

我遇到了快递问题,我不知道如何解决。我希望能够将信息从控制器传递到部分视图(标题)。问题是,当我访问控制器中呈现的视图以外的视图时,它会中断。如何将信息传递给一个视图并使其在所有视图中都起作用。

    const indexController = (req, res) => {
      let emailSession;
      if(req.session.userLogged == undefined){
          emailSession = "";
      } else {
          emailSession = req.session.userLogged.email
      }

      db.Users.findOne({
          where: {email: emailSession}
      }).then((data) => {
        res.render('index', {data}) //I want here to send the same variable to all of my views that has the same header, not just the index view
      )
    }
  <nav>
    <% if(data.info == "something") {%>
      <a href="">Dashboard</a>
    <% } %>
  </nav>

标签: javascriptmysqlexpresssessionejs

解决方案


推荐阅读