router / Function

readRouteData

Generic types:T

Read the current value of the given token from the data object of a route.

See Also

Presentation

function readRouteData(data: Data, token: RouteDataToken<T>): T | undefined;

Returns

T | undefined -

the value, or undefined if such value is not defined

Parameters

NameTypeDescription
data
Data

the data object from ActivatedRoute or ActivatedRouteSnapshot

token
RouteDataToken<T>

the target token to retrieve value of

Example usage

export const NAV_STATUS = new RouteDataToken<NavStatus>("NAV_STATUS");
export const PAGE_ROUTES: Routes = [
  {
    path: "",
    component: PageComponent,
    data: compileRouteData([
      defineRouteData({
        token: NAV_STATUS,
        value: NavStatus.Collapsed,
      }),
    ]),
  },
]
const route = this.activatedRoute.snapshot;
const value = readRouteData(route.data, NAV_STATUS);