Skip to content

RouteGroup

Class for grouping related routes and managing their state. Allows to organize routes into hierarchical structures.

Constructor

ts
newRouteGroup(routes: TRoutesCollection)

Accepts an object with a collection of routes/groups. Routes can be either regularRouteobjects or other entities, such asRouteGrouporVirtualRoute.

Basic example

ts
constroutesGroup=newRouteGroup({index:newRoute('/', { index:true}),fruits:newRoute('/fruits'),zombies:newRoute('/zombies'),memes:newRouteGroup({index:newRoute('/memes', { index:true}),list:newRoute('/memes/list'),create:newRoute('/memes/create'),edit:newRoute('/memes/edit/:id'),}),})

Methods and properties

isOpened: booleancomputed.struct

Returnstrueif at least one route in the group is open.

Example:

ts
constgroup=newRouteGroup({home:newRoute('/'),about:newRoute('/about')});group.routes.home.open();group.isOpened;// true

indexRoute: Route | undefinedcomputed.struct

First foundindexroute defined byisIndexproperty

Example:

ts
constfruits=newRouteGroup({list:newRoute('/fruits', { index:true}),details:newRoute('/fruits/:id'),});fruits.routes.list===fruits.indexRoute;// true

open(...args: any[]): void

Main navigation method for the group. Behavior:

  1. Looks for an index route (with theindex: trueflag) in the group
  2. If an index route is found, opens it
  3. If no index route is found, tries to open the last nested group
  4. If there are no routes in the group, displays a warning (in DEV mode)

Example:

ts
constgroup=newRouteGroup({index:newRoute('/', { index:true}),other:newRoute('/other')});group.open();// Navigates to /// Sending argumentsconstparamGroup=newRouteGroup({index:newRoute('/user/:id', { index:true})});paramGroup.open({ id:42});// /user/42

Released under the MIT License.