简体   繁体   中英

Grouping routes with Flow Router in Meteor

In Flow Router, I have some routes

  • /projects/project-name
  • /projects/project-name/tasks
  • /projects/project-name/tasks/deleted-tasks
  • /projects/project-name/tasks/completed-tasks
  • /projects/project-name/tasks/labels/school
  • /projects/project-name/tasks/labels/football
  • /projects/project-name/tasks/labels/training
  • /projects/project-name/tasks/labels/personal
  • [...]

So almost all of my routes should share most of the same characteristics.

Are there any tricks to group my routes, so I do now have to check if the project exists in every single route or if can I say that some routes build upon other routes, so I do not have to write the long paths for all the routes?

I have found Flow Router, but it doesn't seem that's right tool to accomplish what I need.

Flow router definitely has the ability to group your routes. You can group them as follows -

var projectRoutes = FlowRouter.group({
  prefix: '/projects/project-name',
  name: 'projects',
});

To handle routers within this group, you can add

// route for /projects/project-name
projectRoutes.route('/', {
  action: function() {
    BlazeLayout.render(...);
  }
});

// route for /projects/project-name/tasks
projectRoutes.route('/tasks', {
  action: function() {
    BlazeLayout.render(...);
  }
});

This is just an example for grouping your routes.

You can read more here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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