简体   繁体   English

使用单页时,如何在所有路线中同时添加header.html和footer.html?

[英]How to add both a header.html and a footer.html to all your routes when using singlepage?

We currently have a header.html and a footer.html that we include in our base.html that is loaded in the / route of our website. 目前,我们的base.html中包含的header.html和footer.html已加载到网站的/路由中。 We're using a single page design and thus we don't reload base.html at any time other than when initially loading the page. 我们使用的是单页设计,因此除了最初加载页面时,我们不会在任何时候重新加载base.html。 In base.html we have a div with an id that we use to load all our html content with jQuery to. 在base.html中,我们有一个带有ID的div,用于将jQuery的所有html内容加载到其中。 The problem we're facing now is that fact that accessing a route directly bypasses the load of header, and thus our jQuesry-scripts and bootstrap etc., and then the page looks like crap and doesn't work properly. 我们现在面临的问题是,直接访问路由会绕过标头的负载,从而绕过我们的jQuesry-scripts和bootstrap等,然后页面看起来像废话,无法正常工作。 We figured we could remove the visual URL-change completely and use madeup route-names in our routes instead. 我们认为可以完全删除可视URL更改,而在我们的路由中使用虚构的路由名称。 But that feels like an overly complicated and not neccessarily secure way of doing it. 但这听起来像是一种过于复杂且不必要的安全方式。 Ideally we would like to be able to know if the request is not coming from where it's supposed to. 理想情况下,我们希望能够知道请求是否不是来自预期的请求。

Any ideas of how this can be accomplished? 关于如何实现的任何想法? Or do you generally just expect no one to go to /signup on their own? 还是您通常只是期望没有人独自去/ signup?

I use a Nav component which renders the "chrome" around the page. 我使用了Nav组件,该组件在页面周围呈现“ chrome”。

export class Nav extends Component {
  render = () => {
    return (
      <div>
        <rb.Navbar>
          <rb.Navbar.Header>
            <rb.Navbar.Brand>
              <a href="#">aktai</a>
            </rb.Navbar.Brand>
          </rb.Navbar.Header>
        </rb.Navbar>
        {this.props.children}
      </div>)
  }
}

I mount it to all routes in React Router: 我将其安装到React Router的所有路由中:

const router = (
  <Router history={browserHistory}>
      <Route component={Nav}>
        <Route path="/folders" component={Folders}/>
      </Route>
  </Router>
)

You can also call it like: 您也可以这样称呼:

<Nav>
  <h1>welcome to my site</h1>
  This is a place
</Nav>

Any component which renders this.props.children will work like that. 呈现this.props.children任何组件都将this.props.children工作。

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

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