ScullyRoutesService
TheScullyRoutesService provides methods and observables that give you access to all routes rendered by Scully. This allows you to build dynamic navigation, sitemaps, breadcrumbs, and more based on your generated static routes.
Overview
When Scully builds your site, it creates ascully-routes.json file containing metadata about all generated routes. The ScullyRoutesService loads this file and exposes the route data through RxJS observables, making it easy to integrate route information into your Angular application.
Installation
The service is automatically provided when you importScullyLibModule:
ScullyRoute Interface
All routes returned by the service conform to theScullyRoute interface:
Observables
allRoutes$
Returns all routes generated by Scully, both published and unpublished.available$
Returns only published routes (routes wherepublished is not false).
unPublished$
Returns only unpublished routes (routes wherepublished is explicitly false).
topLevel$
Returns only top-level routes (routes without additional path segments)./blog- included (top-level)/about- included (top-level)/blog/post-1- not included (has subroute)/blog/post-2- not included (has subroute)
Methods
getCurrent()
Returns an observable that emits the route information for the currently active route. Automatically updates when navigation occurs.reload()
Forces a reload of thescully-routes.json file. Useful if routes are added dynamically.
Common Use Cases
Building a Navigation Menu
Creating a Blog Archive
Building Breadcrumbs
Filtering Routes by Tag
Custom Route Properties
You can add custom properties to routes in your markdown frontmatter or route configuration:ScullyRoute interface:
Error Handling
The service handles missing route files gracefully:scully-routes.json file is not found, the service logs a warning:
Best Practices
Use async pipe
Use async pipe
Always use the
async pipe in templates to automatically handle subscriptions:Cache transformed data
Cache transformed data
Use
shareReplay() when transforming route data to avoid recomputing:Add custom metadata
Add custom metadata
Extend routes with custom properties for filtering, sorting, and grouping:
Handle missing routes gracefully
Handle missing routes gracefully
Always check if a route exists before using it:
Source Code
View the complete source code:Related
Scully Library
Learn about the Angular library overview
Transfer State
Cache application state during rendering

