简体   繁体   English

如何在使用机车构建的已经存在的Node.js项目中将新的URL添加到route.js文件中?

[英]How to add a new url to the routes.js file in an already existing Node.js project built using locomotive?

module.exports = function routes() {
this.root('pages#main');
this.match('/status', 'pages#status');

this.resources('paper');
this.resources('tempform');
};

How to add a new url suppose "paper/domain" to my application? 如何在我的应用程序中添加一个新的url(假设“ paper / domain”)?

Can someone please explain how I can add this? 有人可以解释一下我如何添加吗? I have read the Locomotive guide but couldn't figure out the solution. 我已经阅读过机车指南,但找不到解决方案。

In Locomotive routes are configured in config/routes.js . 在机车中,路由是在config/routes.jsconfig/routes.js

this.match('pages/:home', { controller: 'PageController', action: 'show' });

And then in the controllers directory create a new file with 然后在controllers目录中创建一个新文件

var PageController = new Controller();
module.exports = PageController;
PageController.show = function() {
  this.render();
}

From the LocomotiveJS guide: http://locomotivejs.org/guide/namespaces/ 从LocomotiveJS指南中: http : //locomotivejs.org/guide/namespaces/

You can use namespaces to group several controllers under a namespace (eg example.com/namespace/). 您可以使用名称空间将一个名称空间下的多个控制器分组(例如example.com/namespace/)。 In your case, you would want something like 在您的情况下,您会想要类似

this.namespace('paper', function() {
  this.match('domain', 'yourController#yourAction');
});

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

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