Skip to content

Latest commit

 

History

History
67 lines (56 loc) · 1.96 KB

group.md

File metadata and controls

67 lines (56 loc) · 1.96 KB

group method

Use group routes for better route organization.

.group(options)

  • options {Object} - [Optional]
  • options.name {String} - [Optional] Route's name
  • options.prefix {String} - [Optional] Route prefix
  • options[prop-name] {Any} - [Optional] Any property which will be available inside route call
  • options[hook-name] {Function} - [Optional] See all available hooks
  • Returns {Group}
const adminRoutes = FlowRouter.group({
  prefix: '/admin',
  name: 'admin',
  triggersEnter: [(context, redirect) => {
    console.log('running group triggers');
  }]
});

// handling /admin/ route
adminRoutes.route('/', {
  name: 'adminIndex',
  action() { /* ... */ }
});

// handling /admin/posts
adminRoutes.route('/posts', {
  name: 'adminPosts',
  action() { /* ... */ }
});

Nested Group

const adminRoutes = FlowRouter.group({
    prefix: '/admin',
    name: 'admin'
});

const superAdminRoutes = adminRoutes.group({
    prefix: '/super',
    name: 'superadmin'
});

// handling /admin/super/post
superAdminRoutes.route('/post', {
    action() { /* ... */ }
});

Get group name

FlowRouter.current().route.group.name

This can be useful for determining if the current route is in a specific group (e.g. admin, public, loggedIn) without needing to use prefixes if you don't want to. If it's a nested group, you can get the parent group's name with:

FlowRouter.current().route.group.parent.name

Further reading