Skip to content Skip to sidebar Skip to footer

Meteor Js Iron Router, Route Sub Directory

I am working on a admin and client portal in Meteor JS using Iron:Router. I know i can create a route using: this.route('tasks',{path:'/projects', layoutTemplate: 'adminLayout'});

Solution 1:

All the paths you have can coexist in one app quite happily. The router (or your browser) doesn't have any concept of directories/subdirectories, all it understands are strings and regular expressions. The nesting is purely something we (should) create to enable ourselves to understand how an app/api(/codebase, etc) is structured.

As Sasikanth points out that is not the full error message. However looking at packages/iron_middleware-stack/lib/middleware_stack.js line 31 it's easy to confirm what is happening:

thrownewError("Handler with name '" + name + "' already exists.");

This is within the Router.route function, which is documented here.

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

So for the code you included above, you provide explicit paths. Therefore the first parameter is the route name. These must be unique as they are used to lookup the path in the pathFor, urlFor and linkTo helpers. As you are not providing an explicit template option, the name is also used for that, but your code is throwing this exception before it gets that far.

I think what you were trying to achieve is this:

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'});

Post a Comment for "Meteor Js Iron Router, Route Sub Directory"