简体   繁体   English

NodeJs - 在所有页面上共享类别列表

[英]NodeJs - Sharing a list of categories across all pages

I am building a website where the navigation bar contains a drop down list which contains the following categories:我正在构建一个网站,其中导航栏包含一个包含以下类别的下拉列表:

  1. Web Development Web开发
  2. Mobile Development移动开发
  3. Desktop Development桌面开发
  4. Programming编程

Do i need to retrieve the above categories every time a new page of my application is requested.每次请求我的应用程序的新页面时,我是否需要检索上述类别。 For example:例如:

  • For the home page i retrieve the categories from the database.对于主页,我从数据库中检索类别。
  • For add product page i also retrieve the categories from the database.对于添加产品页面,我还从数据库中检索类别。

I know that my approach is not efficient, Is there a better way to accomplish it.我知道我的方法效率不高,有没有更好的方法来实现它。

Kindly note that i am using pug template engine请注意,我正在使用 pug 模板引擎

Thanks谢谢

the better way to get what you want is using Redux, it lets you share variables above all the code.获得所需内容的更好方法是使用 Redux,它允许您在所有代码之上共享变量。 it's simply to implement.它只是执行。

you can see the documentation here您可以在此处查看文档

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

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