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 regularRoute
objects or other entities, such asRouteGroup
orVirtualRoute
.
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: boolean
computed.struct
Returnstrue
if 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 | undefined
computed.struct
First foundindex
route defined byisIndex
property
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:
- Looks for an index route (with the
index: true
flag) in the group - If an index route is found, opens it
- If no index route is found, tries to open the last nested group
- 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