Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor JS Iron路由器,路由子目录_Javascript_Meteor_Iron Router - Fatal编程技术网

Javascript Meteor JS Iron路由器,路由子目录

Javascript Meteor JS Iron路由器,路由子目录,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,我正在使用Iron:Router开发Meteor JS中的管理和客户端门户 我知道我可以使用以下方法创建路线: this.route('tasks',{path:'/projects', layoutTemplate: 'adminLayout'}); 但是否可以使用子目录创建路由,例如: this.route('tasks',{path:'/admin/projects', layoutTemplate: 'adminLayout'}); 这样我也可以有一个子目录: this.route(

我正在使用Iron:Router开发Meteor JS中的管理和客户端门户

我知道我可以使用以下方法创建路线:

this.route('tasks',{path:'/projects', layoutTemplate: 'adminLayout'});
但是否可以使用子目录创建路由,例如:

this.route('tasks',{path:'/admin/projects', layoutTemplate: 'adminLayout'});
这样我也可以有一个子目录:

this.route('/admin/projects', {name: 'admin.projects', template: 'projects', layoutTemplate: 'adminLayout'}


感谢您的输入。

您拥有的所有路径都可以在一个应用程序中非常愉快地共存。 路由器(或您的浏览器)没有任何目录/子目录的概念,它只理解字符串和正则表达式。嵌套纯粹是我们(应该)创建的东西,以使我们能够理解app/api(/codebase等)是如何构造的

正如Sasikanth指出的,这并不是完整的错误信息。然而,通过观察很容易确认发生了什么:

    throw new Error("Handler with name '" + name + "' already exists.");
这在Router.route功能中,有文档记录

因此,对于上面包含的代码,您提供了显式路径。因此,第一个参数是路由名称。它们必须是唯一的,因为它们用于查找pathFor、urlFor和linkTo帮助程序中的路径。由于您没有提供显式模板选项,因此名称也会用于该选项,但您的代码会在异常出现之前抛出该异常

我认为你想要实现的是:

this.route('/projects', {name: 'projects', template: 'tasks',  layoutTemplate: 'adminLayout'});
this.route('/admin/projects', {name: 'admin.projects', template: 'tasks', layoutTemplate: 'adminLayout'});
this.route('/client/projects', {name: 'client.projects', template: 'tasks', layoutTemplate: 'adminLayout'});

这是完整的错误报告吗?看起来这只是错误的一半,如果不是的话,你可以发布完整的错误或错误的屏幕截图。还可以尝试更改路由的名称,对于所有使用相同名称的路由
任务
,我认为路由名称应该有所不同。我已经将错误消除,错误日志实际上来自重复的路由(管理员/客户端)这就是我想区分它们的原因。但现在的问题是,这条路线无法解决。Iron:Router可以识别路由,但不知道加载哪个模板,因此页面处于加载状态,只加载了CSS。他们都阅读模板任务的原因是因为我在这里复制并粘贴了它们。他们都将使用不同的模板。仅供参考。您好,请彻底分离控制台错误,该错误来自重复的路线,该路线未发布,如我在前面的评论中所述。你对我试图实现的目标是正确的,我已经纠正了这一点,但在加载CSS后,应用程序陷入了加载阶段。我已经将我的代码更改为:this.route('/admin/projects',{name:'admin.projects',template:'projects',layoutTemplate:'adminLayout'}您可能应该将路由器配置为与
路由器一起使用布局。configure({layoutTemplate:'adminLayout'})同时,为了简单起见,现在删除“<代码>名称>代码>属性。考虑取消您的命名约定,即它是代码> /项目/管理< /代码>和<代码> /项目/客户端< /代码>。至于您所遇到的实际问题,请确保在您中只有一个模板名为“代码>任务< /代码>。r项目文件,有时会出现重复并导致奇怪的错误。如果这不起作用,我们可能需要您将一些错误粘贴到控制台或meteor服务器中。刚才也注意到了,但您正在执行
此操作。route
而不是
Router.route
——我认为这在前几个版本中已被弃用——请参阅official进入指南
Router.route('/post/:_id', {
  // The name of the route.
  // Used to reference the route in path helpers and to find a default template
  // for the route if none is provided in the "template" option. If no name is
  // provided, the router guesses a name based on the path '/post/:_id'
  name: 'post.show',

  // To support legacy versions of Iron.Router you can provide an explicit path
  // as an option, in case the first parameter is actually a route name.
  // However, it is recommended to provide the path as the first parameter of the
  // route function.
  path: '/post/:_id',

  // If we want to provide a specific RouteController instead of an anonymous
  // one we can do that here. See the Route Controller section for more info.
  controller: 'CustomController',

  // If the template name is different from the route name you can specify it
  // explicitly here.
  template: 'Post',

  // and more options follow
this.route('/projects', {name: 'projects', template: 'tasks',  layoutTemplate: 'adminLayout'});
this.route('/admin/projects', {name: 'admin.projects', template: 'tasks', layoutTemplate: 'adminLayout'});
this.route('/client/projects', {name: 'client.projects', template: 'tasks', layoutTemplate: 'adminLayout'});