Iron Router: When to use string VS symbol for controller name in this.route()

StackOverflow https://stackoverflow.com/questions/21368630

  •  03-10-2022
  •  | 
  •  

Вопрос

Can someone help explain when to use a string VS a symbol for the name in this example. In my code I have my controller defined as:

PostShowController = RouteController.extend({
   template: 'userShow'
 });

// Why the difference, my code only works with the single quotes around PostShowController, but Telescope uses the symbol way: https://github.com/SachaG/Telescope/blob/master/lib/router.js

Router.map(function () {

   // provide a String to evaluate later
   this.route('postShow', {
     path: '/:name',
     controller: 'PostShowController'
   });

   // provide the actual controller symbol if it's already defined
   this.route('postShow', {
    path: '/:name',
    controller: PostShowController
   });
});
Это было полезно?

Решение

As it says in the example("to evaluate later") the string is to be used when you will define the controller in some place after "Router.map(...)" or in some other file.

Considering that Meteor loads your files in a specific order, lets say your files from the router load before your controllers definitions, you would get an error using the symbol because the controller wouldn't be defined.

To avoid the error you should use string when defining your routes and the controllers it is in another file or after Router.map(...).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top