一直试图解决这个问题,但不能为我的生活找出我所缺少的东西。
所以我想设置keystone,但是想在前端使用angular,我想避免每次重新加载页面。
角度跑得非常好而且非常快。但是现在我正在尝试在后端为部分设置路由,虽然我可以设法让它们设置为回答,但是我不能让它们只是发送部分,无论我做什么它发送整个页面对我来说。与HTML,身体,头部。
到目前为止,我已经设法找出我需要一条路线,因此导入了我的uiview目录并添加了以下路线:
var keystone = require('keystone');
var middleware = require('./middleware');
var importRoutes = keystone.importer(__dirname);
// Common Middleware
keystone.pre('routes', middleware.initLocals);
keystone.pre('render', middleware.flashMessages);
// Import Route Controllers
var routes = {
views: importRoutes('./views'),
uiviews: importRoutes('/uiviews'),
};
// Setup Route Bindings
exports = module.exports = function (app) {
// Views
app.get('/', routes.views.index);
app.get('/uiviews/index',routes.uiviews.index);
app.get('/blog/:category?', routes.views.blog);
app.get('/blog/post/:post', routes.views.post);
app.get('/gallery', routes.views.gallery);
app.all('/contact', routes.views.contact);
// NOTE: To protect a route so that only admins can see it, use the requireUser middleware:
// app.get('/protected', middleware.requireUser, routes.views.protected);
};
我认为正在发生的事情是预编译器(keystone.pre(' routes',middleware.initLocals);)获取它并将其包装为它认为的所有方式,但我不确定。
我甚至尝试用我的uiroute在./routes中创建一个uiviews.js,但这给了我404错误
var keystone = require('keystone');
var middleware = require('./middleware');
var importRoutes = keystone.importer(__dirname);
// Import Route Controllers
var routes = {
uiviews: importRoutes('/uiviews'),
};
// Setup Route Bindings
exports = module.exports = function (app) {
// Views
console.log('uiroutes added');
app.get('/uiview/index',routes.uiviews.index);
// NOTE: To protect a route so that only admins can see it, use the requireUser middleware:
// app.get('/protected', middleware.requireUser, routes.views.protected);
};
有什么想法吗?
答案 0 :(得分:0)
这更像是一个表达问题,而不是keystone.Js 你没有说过你想要的部分路由器。并且都没有共享该处理程序的渲染代码。
任何方式确保您使用的模板不包含任何其他模板。特别是default.jade
答案 1 :(得分:0)
我终于弄清楚了我错过了什么。
从技术上讲,控制发送内容的不是keystone.js,而是把手。除了我,这对每个人来说都是显而易见的。
然而,诀窍是告诉把手不要包含布局,这是使用{layout:false}完成的。所以我的uiview路线看起来像这样(最后一条小线就是神奇的):
var keystone = require('keystone');
exports = module.exports = function(req, res) {
console.log("request for index received");
var view = new keystone.View(req, res),
locals = res.locals;
console.log(locals);
// Render the view
console.log(view)
view.render('uiviews/index', {layout: false});
};
使用index.js路由器,如下所示:
var keystone = require('keystone');
var middleware = require('./middleware');
var importRoutes = keystone.importer(__dirname);
// Common Middleware
keystone.pre('routes', middleware.initLocals);
keystone.pre('render', middleware.flashMessages);
// Import Route Controllers
var routes = {
views: importRoutes('./views'),
uiviews: importRoutes('/uiviews'),
};
// Setup Route Bindings
exports = module.exports = function (app) {
// Views
console.log('index added');
app.get('/', routes.views.index);
app.get('/partners', routes.views.partners);
app.get('/blog/:category?', routes.views.blog);
app.get('/blog/post/:post', routes.views.post);
app.get('/gallery', routes.views.gallery);
app.get('/philosophy', routes.views.philosophy)
app.get('/socialmedia', routes.views.socialmedia)
app.all('/contact', routes.views.contact);
app.get('/uiviews/index', routes.uiviews.index)
// NOTE: To protect a route so that only admins can see it, use the requireUser middleware:
// app.get('/protected', middleware.requireUser, routes.views.protected);
};
现在您可以调用[host] / uiviews / index并仅接收部分路线。