javascript - 是否可以在 Angular JS 中进行服务器端渲染(在旧版本中,即 2.0 之前的版本)?

标签 javascript angularjs reactjs seo nodes

我想用 angularJS 做服务器端渲染。是否可以在旧版本的 angularJS(2.0 之前的版本)中执行此操作?

最佳答案

有一些 npm 模块可以在服务器端解析 AngularJS 模板:

AngularJS-Server is built on jsdom, an implementation of the DOM API for Node, and angularcontext, which provides a lightweight container in which to instantiate your AngularJS application.

After I eventually got a very basic AngularJS example running on the server, I moved on to routing. The first problem I ran into was that jsdom just stubs out the Window object's XMLHttpRequest, so it doesn't do anything. Solution was pretty simple -- modify a line in lib/jsdom/browser/index.js:

XMLHttpRequest: require('../../../../xmlhttprequest').XMLHttpRequest

Your angular app must use html5mode. The reason behind this requirement is that browsers don't send the hashbang fragment to the server.

So for example, rendering on the server side http://domain.com/url#blah will just render http://domain.com/url.

The library exposes several angular services, which will let you compile angular templates inside node

引用资料

关于javascript - 是否可以在 Angular JS 中进行服务器端渲染(在旧版本中,即 2.0 之前的版本)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35174642/

相关文章:

reactjs - React-router:如何使用 Link 获取先前的路径

javascript - Mongoose保存返回正确的保存对象,但它没有保存到数据库

javascript - 如何使用 JavaScript 设置带前缀的 CSS3 过渡效果?

javascript - 将 C# 字典读取到 Javascript 对象

javascript - 无尽的动画、requestAnimationFrame 和调用堆栈限制

javascript - 恢复保存的 Angular HTML

angularjs 指令单元测试因controllerAs、bindToController 和isolateScope() 失败

javascript - 如何在reactjs中成功登录后重定向并阻止未登录的页面?

angularjs - 避免 Angular.js orderBy 默认排序

reactjs - 组件正在更改不受控制的自动完成以进行控制