简体   繁体   English

在节点 js 中渲染页面而不重新加载部分

[英]render a page without reload partials in node js

How to reload the page without reload partials in node js.如何在节点 js 中重新加载页面而不重新加载部分。 I am creating a web application using node js, bootstrap, mongodb and handlebars.我正在使用节点 js、引导程序、mongodb 和车把创建 web 应用程序。 In my partial navbar the active class and js code for changing it into clicked component.在我的部分导航栏中,活动的 class 和用于将其更改为单击组件的 js 代码。 when I render a page inside this the whole document is reloading and active class changing is uneffective in this case.当我在其中呈现页面时,整个文档正在重新加载,并且在这种情况下,主动 class 更改无效。 I think it will be fixed with avoid reloading partials.我认为它将通过避免重新加载部分来解决。 There is any way to avoid reloading partials when page rendered.有任何方法可以避免在页面呈现时重新加载部分。

I'm working on assumptions here as you haven't posted any code, I assume that:我在这里进行假设,因为您没有发布任何代码,我假设:

  • You are using Handlebars to render the partials on your Server?您正在使用 Handlebars 在您的服务器上渲染部分内容吗? (not on the client) (不在客户端)
  • You have setup separate routes on NodeJS (are you using express?) so each route serves a different page, eg "/Index", "/About", "/Privacy", "/Contact" etc.您在 NodeJS 上设置了单独的路由(您使用的是 express 吗?),因此每条路由都服务于不同的页面,例如“/Index”、“/About”、“/Privacy”、“/Contact”等。

If my assumptions are true, each route on your server is providing an entire web page.如果我的假设是正确的,那么您服务器上的每条路由都提供了一个完整的 web 页面。 It must re-load the partial because the client expects a complete html page for that route, and whenever the client changes route the server must provide a new page;它必须重新加载部分,因为客户端期望该路由的完整 html 页面,并且每当客户端更改路由时,服务器必须提供新页面; if it didn't reload the partial then your navbar would be missing.如果它没有重新加载部分,那么您的导航栏将会丢失。

If you want a more seamless experience where the navbar stays there and you can modify its state, and only the remainder of the page reloads, you ought to try the Single Page Application approach.如果您想要导航栏保持在那里的更无缝体验,并且您可以修改其 state,并且仅重新加载页面的其余部分,您应该尝试单页应用程序方法。 Frameworks such as Angular, React, VueJS or Svelte are designed with this approach in mind. Angular、React、VueJS 或 Svelte 等框架在设计时就考虑了这种方法。 Your routing and page templating is done client-side rather than server-side, but you can use a combination of both (I use Handlebars and VueJS)您的路由和页面模板是在客户端而不是服务器端完成的,但您可以将两者结合使用(我使用 Handlebars 和 VueJS)

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

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