Reducing redundancy in routing breadcrumb paths with slugs?


#1

I have a variety of paths like this:

/class/:classSlug/student
/class/:classSlug/teacher
/class/:classSlug/teacher/:_id
/class/:classSlug/student/:_id
/class/:classSlug/lecture/:urlDate/:lectureSlug

I am having a very annoying time with redundancy here and routing. Originally I constructed my schemas like so:

Student.attachSchema(new SimpleSchema({
  // ...
  classes: {
    type: [Object],
    minCount: 1
  },
  "classes.$._id": {
    type: String,
    allowedValues: function() {
      return Classes.find().map(function (doc) {
        return doc._id;
      });
    }
  },
  "classes.$.slug": {
    type: String,
    allowedValues: function() {
      return Classes.find().map(function (doc) {
        return doc.slug;
      });
    }
  }
}));

However, it is possible for the slugs to change. Ideally, what I’d like to do is pass the full class object on the before action on each url. Eg, mutate the this.data of every template under that route to contain a class object.

Is this possible? Suggestions?