The most common use of route collections is to group routes with a common path prefix.
Copy class RouteCollection
{
constructor (string prefix , array routes = [] , array collections = []);
addRoute (Route route);
addRoutes (Route[] routes);
addCollection (RouteCollection collection);
addCollections (RouteCollection[] collections);
findRouteByPath (string path);
findRouteByName (string name , bool deep = false );
findCollectionByPrefix (string prefix);
getRoutes () : Route [];
getCollections () : RouteCollection [];
getFlattenedRoutes () : Route [];
getFlattenedCollections () : RouteCollection [];
getPathPrefix () : string ;
getParentCollection () : RouteCollection | null ;
setPathPrefix (string prefix);
setParentCollection (RouteCollection collection);
}
Example: Grouping routes with a shared path prefix
Copy let routes = new RouteCollection ( '/sandbox' , [
// Matches #/sandbox/index
new Route ( 'sandbox.index' , '/index' , 'Sandbox.Sandbox.index' ) ,
// Matches #/sandbox/demo
new Route ( 'sandbox.demo' '/demo' , 'Sandbox.Sandbox.demo' )
];
Example: Chaining collections declaratively
Copy let routes = new RouteCollection ( '/sandbox' , [
// Matches #/sandbox/index
new Route ( 'sandbox.index' , '/index' , 'Sandbox.Sandbox.index' )
] , [
new RouteCollection ( '/section' , [
// Matches #/sandbox/section/demo
new Route ( 'sandbox.demo' , '/demo' , 'Sandbox.Sandbox.demo' )
])
]);
Example: Chaining collections imperatively
Copy let sandboxRoutes = new RouteCollection ( '/sandbox' , [
// Matches #/sandbox/index
new Route ( 'sandbox.index' , '/index' , 'Sandbox.Sandbox.index' )
]);
let sectionRoutes = new RouteCollection ( '/section' , [
// Matches #/section/demo
new Route ( 'sandbox.demo' , '/demo' , 'Sandbox.Sandbox.demo' )
]);
sandboxRoutes .addCollection (sectionRoutes);
// sandbox.index still matches #/sandbox/index
// sandbox.demo now matches #/sandbox/section/demo