Single Source of Truth
Single Source of Truth
π¨βπΌ We want a single source of truth for route names and paths without enums.
Using
as const lets us derive types directly from the runtime object.π¨ Open
and:
- Add
as constto theroutesobject soroutes.homestays the literal'/' - Create
RouteNamefrom the keys ofroutesandRoutePathfrom the values - Remove the
@ts-expect-erroroncedefaultRoute: '/'type-checks - Implement
getRoutePath(name: RouteName): RoutePathso it returns the path for that name fromroutes - Export
routes,defaultRoute, andgetRoutePathby name
Completion criteria
- Named exports:
routes,defaultRoute,getRoutePath getRoutePath('home')β'/'getRoutePath('login')β'/login'getRoutePath('settings')β'/settings'
π°
keyof typeof gives you the keys; indexed access gives you the values.

